結果

問題 No.1344 Typical Shortest Path Sum
ユーザー tentententen
提出日時 2023-01-12 09:28:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 2,515 bytes
コンパイル時間 3,914 ms
コンパイル使用メモリ 86,736 KB
実行使用メモリ 53,516 KB
最終ジャッジ日時 2023-08-24 18:18:08
合計ジャッジ時間 11,492 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,536 KB
testcase_01 AC 45 ms
49,368 KB
testcase_02 AC 44 ms
49,472 KB
testcase_03 AC 46 ms
49,404 KB
testcase_04 AC 45 ms
49,484 KB
testcase_05 AC 45 ms
47,500 KB
testcase_06 AC 44 ms
49,368 KB
testcase_07 AC 46 ms
49,376 KB
testcase_08 AC 44 ms
49,456 KB
testcase_09 AC 45 ms
49,368 KB
testcase_10 AC 43 ms
49,340 KB
testcase_11 AC 44 ms
49,472 KB
testcase_12 AC 45 ms
49,416 KB
testcase_13 AC 43 ms
49,404 KB
testcase_14 AC 44 ms
49,720 KB
testcase_15 AC 44 ms
49,528 KB
testcase_16 AC 54 ms
51,284 KB
testcase_17 AC 44 ms
49,520 KB
testcase_18 AC 44 ms
49,584 KB
testcase_19 AC 44 ms
49,408 KB
testcase_20 AC 43 ms
49,396 KB
testcase_21 AC 46 ms
49,868 KB
testcase_22 AC 44 ms
49,348 KB
testcase_23 AC 45 ms
49,356 KB
testcase_24 AC 45 ms
49,460 KB
testcase_25 AC 43 ms
49,528 KB
testcase_26 AC 45 ms
49,484 KB
testcase_27 AC 44 ms
49,412 KB
testcase_28 AC 45 ms
49,408 KB
testcase_29 AC 44 ms
49,472 KB
testcase_30 AC 44 ms
47,704 KB
testcase_31 AC 42 ms
47,532 KB
testcase_32 AC 45 ms
49,304 KB
testcase_33 AC 43 ms
49,476 KB
testcase_34 AC 44 ms
49,460 KB
testcase_35 AC 45 ms
49,468 KB
testcase_36 AC 44 ms
49,436 KB
testcase_37 AC 44 ms
49,864 KB
testcase_38 AC 44 ms
49,580 KB
testcase_39 AC 46 ms
49,460 KB
testcase_40 AC 72 ms
51,208 KB
testcase_41 AC 75 ms
51,588 KB
testcase_42 AC 65 ms
51,280 KB
testcase_43 AC 67 ms
51,264 KB
testcase_44 AC 66 ms
51,480 KB
testcase_45 AC 65 ms
51,384 KB
testcase_46 AC 64 ms
51,528 KB
testcase_47 AC 67 ms
51,452 KB
testcase_48 AC 65 ms
51,416 KB
testcase_49 AC 65 ms
51,420 KB
testcase_50 AC 65 ms
51,444 KB
testcase_51 AC 65 ms
51,420 KB
testcase_52 AC 65 ms
51,388 KB
testcase_53 AC 67 ms
51,392 KB
testcase_54 AC 66 ms
51,164 KB
testcase_55 AC 67 ms
51,756 KB
testcase_56 AC 74 ms
51,120 KB
testcase_57 AC 66 ms
51,504 KB
testcase_58 AC 78 ms
51,476 KB
testcase_59 AC 66 ms
51,204 KB
testcase_60 AC 50 ms
49,900 KB
testcase_61 AC 45 ms
49,628 KB
testcase_62 AC 110 ms
53,516 KB
testcase_63 AC 59 ms
50,564 KB
testcase_64 AC 73 ms
50,688 KB
testcase_65 AC 111 ms
52,868 KB
testcase_66 AC 109 ms
52,932 KB
testcase_67 AC 110 ms
51,264 KB
testcase_68 AC 57 ms
50,824 KB
testcase_69 AC 59 ms
50,392 KB
testcase_70 AC 45 ms
49,492 KB
testcase_71 AC 45 ms
49,364 KB
testcase_72 AC 44 ms
49,420 KB
testcase_73 AC 43 ms
49,412 KB
testcase_74 AC 44 ms
49,356 KB
testcase_75 AC 43 ms
47,432 KB
testcase_76 AC 44 ms
49,532 KB
testcase_77 AC 44 ms
49,700 KB
testcase_78 AC 45 ms
49,544 KB
testcase_79 AC 48 ms
49,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static final long MAX = 1000000000000L * 100;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[][] costs = new long[n][n];
        for (int i = 0; i < n; i++) {
            Arrays.fill(costs[i], Long.MAX_VALUE / 2);
            costs[i][i] = 0;
        }
        for (int i = 0; i < m; i++) {
            int s = sc.nextInt() - 1;
            int t = sc.nextInt() - 1;
            long c = sc.nextLong();
            costs[s][t] = Math.min(costs[s][t], c);
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    costs[j][k] = Math.min(costs[j][k], costs[j][i] + costs[i][k]);
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            long sum = 0;
            for (int j = 0; j < n; j++) {
                if (costs[i][j] < MAX) {
                    sum += costs[i][j];
                }
            }
            sb.append(sum).append("\n");
        }
        System.out.print(sb);
    }
    
}

class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0