code:
1 import java.util.*; 2 import java.io.*; 3 class Main 4 { 5 static int[][] map = null; 6 static int pointNum; 7 8 public static void main(String[] arge) throws IOException 9 { 10 Scanner input = new Scanner(System.in); 11 BufferedReader cin = new BufferedReader(new InputStreamReader(System.in)); 12 pointNum = input.nextInt(); 13 14 map = new int[pointNum+1][pointNum+1]; 15 int max = 0,value = 0; 16 17 for(int i = 0;i<map.length;i++) 18 Arrays.fill(map[i],Integer.MAX_VALUE/2); 19 20 for(int i = 1;i<pointNum;i++) 21 { 22 String str = cin.readLine(); 23 24 String[] num = str.split(" "); 25 26 map[Integer.parseInt(num[0])][Integer.parseInt(num[1])] = Integer.parseInt(num[2]); 27 map[Integer.parseInt(num[1])][Integer.parseInt(num[0])] = Integer.parseInt(num[2]); 28 29 } 30 31 doWork(); 32 33 for(int i = 1;i<map.length;i++) 34 for(int j = i+1;j<map.length;j++) 35 { 36 if(map[i][j]<=Integer.MAX_VALUE/2) 37 max = map[i][j] > max ? map[i][j]:max; 38 } 39 40 41 for(int i = 1;i<=max;i++) 42 { 43 value = value + i + 10; 44 } 45 46 sop1(value); 47 } 48 49 public static void doWork() 50 { 51 for(int k = 1;k<pointNum;k++) 52 { 53 for(int i = 1;i<map.length;i++) 54 { 55 for(int j = 1;j<map.length;j++) 56 { 57 58 if(map[i][k] + map[k][j] < map[i][j]) 59 map[i][j] = map[i][k] + map[k][j]; 60 } 61 } 62 } 63 } 64 65 public static void sop1(Object obj) 66 { 67 System.out.println(obj); 68 } 69 }
线下运行结果正确,提交显示运行错误