class Node{ int[] dis; int val = Integer.MAX_VALUE; public Node(int[] dis) { this.dis = dis; } } public class Main {     public static void main(String[] args) {         Scanner sc = new Scanner(System.in);         int[][] dis = new int[6][6];         Node[] node = new Node[6];         for (int i = 0; i < 6; i ++) {             String[] temp = sc.nextLine().split(" ");             for (int j = 0; j < 6; j ++) {                 dis[i][j] = Integer.parseInt(temp[j]);             }             node[i] = new Node(dis[i]);         }         Queue<Node> queue = new LinkedList<>();         queue.offer(node[0]);         node[0].val = 0;         while (! queue.isEmpty()) {          Node temp = queue.poll();          for (int i = 0; i < 6; i ++) {          if (temp.dis[i] != 0 && temp.dis[i] != -1) {          node[i].val = Math.min(node[i].val, temp.val + temp.dis[i]);          queue.offer(node[i]);          }          }         }         for (Node x: node) {          System.out.println(x.val);         }     } } 第二题仅作参考🙁
点赞 1

相关推荐

饿魔:你这为什么gap了半年啊
点赞 评论 收藏
分享
Manayakko:实习和hw履历足够了,如果这还不行,那纯是吃了大环境经济发展问题的亏了
大家都开始春招面试了吗
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务