結果
問題 | No.845 最長の切符 |
ユーザー | htensai |
提出日時 | 2020-01-28 10:39:40 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,327 bytes |
コンパイル時間 | 2,324 ms |
コンパイル使用メモリ | 76,724 KB |
実行使用メモリ | 60,280 KB |
最終ジャッジ日時 | 2023-10-13 10:31:33 |
合計ジャッジ時間 | 10,630 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 127 ms
55,844 KB |
testcase_01 | AC | 129 ms
55,912 KB |
testcase_02 | AC | 128 ms
55,608 KB |
testcase_03 | AC | 123 ms
55,468 KB |
testcase_04 | AC | 125 ms
55,788 KB |
testcase_05 | AC | 126 ms
55,956 KB |
testcase_06 | AC | 122 ms
55,936 KB |
testcase_07 | AC | 127 ms
55,768 KB |
testcase_08 | AC | 166 ms
56,784 KB |
testcase_09 | AC | 133 ms
56,156 KB |
testcase_10 | AC | 516 ms
60,280 KB |
testcase_11 | AC | 224 ms
59,748 KB |
testcase_12 | AC | 202 ms
59,956 KB |
testcase_13 | AC | 176 ms
56,452 KB |
testcase_14 | AC | 169 ms
56,292 KB |
testcase_15 | TLE | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
ソースコード
import java.util.*; public class Main { static HashMap<Integer, Integer>[] graph; static int max = 0; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); graph = new HashMap[n]; for (int i = 0; i < n; i++) { graph[i] = new HashMap<>(); } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; int c = sc.nextInt(); if (!graph[a].containsKey(b) || graph[a].get(b) < c) { graph[a].put(b, c); } if (!graph[b].containsKey(a) || graph[b].get(a) < c) { graph[b].put(a, c); } } for (int i = 0; i < n; i++) { int[] costs = new int[n]; Arrays.fill(costs, -1); search(i, 0, costs); } System.out.println(max); } static void search(int idx, int total, int[] costs) { if (costs[idx] != -1) { return; } max = Math.max(max, total); costs[idx] = total; for (Map.Entry<Integer, Integer> entry : graph[idx].entrySet()) { search(entry.getKey(), total + entry.getValue(), costs); } costs[idx] = -1; } }