結果
| 問題 |
No.1344 Typical Shortest Path Sum
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2023-01-12 09:10:09 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,504 bytes |
| コンパイル時間 | 4,957 ms |
| コンパイル使用メモリ | 87,204 KB |
| 実行使用メモリ | 39,960 KB |
| 最終ジャッジ日時 | 2024-12-23 02:34:17 |
| 合計ジャッジ時間 | 11,479 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 WA * 49 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.stream.*;
public class Main {
static long[] fact;
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] < Long.MAX_VALUE / 2) {
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();
}
}
tenten