結果

問題 No.1344 Typical Shortest Path Sum
ユーザー ks2m
提出日時 2021-01-16 13:54:52
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,172 bytes
コンパイル時間 1,717 ms
コンパイル使用メモリ 76,420 KB
実行使用メモリ 45,284 KB
最終ジャッジ日時 2024-11-27 14:41:50
合計ジャッジ時間 8,000 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);

		long inf = 4000000000000000000L;
		long[][] d = new long[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i != j) {
					d[i][j] = inf;
				}
			}
		}

		for (int i = 0; i < m; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			long c = Long.parseLong(sa[2]);
			d[a][b] = c;
		}
		br.close();

		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
				}
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < n; i++) {
			long ans = 0;
			for (int j = 0; j < n; j++) {
				if (i != j && d[i][j] != inf) {
					ans += d[i][j];
				}
			}
			pw.println(ans);
		}
		pw.flush();
	}
}
0