結果
問題 | No.845 最長の切符 |
ユーザー | tenten |
提出日時 | 2020-08-31 19:38:00 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,859 bytes |
コンパイル時間 | 2,497 ms |
コンパイル使用メモリ | 80,744 KB |
実行使用メモリ | 57,352 KB |
最終ジャッジ日時 | 2024-04-28 10:38:38 |
合計ジャッジ時間 | 7,888 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 121 ms
54,004 KB |
testcase_01 | AC | 123 ms
53,980 KB |
testcase_02 | AC | 110 ms
52,544 KB |
testcase_03 | AC | 112 ms
52,552 KB |
testcase_04 | AC | 126 ms
54,344 KB |
testcase_05 | AC | 122 ms
54,192 KB |
testcase_06 | AC | 115 ms
53,476 KB |
testcase_07 | WA | - |
testcase_08 | AC | 132 ms
54,092 KB |
testcase_09 | AC | 113 ms
53,040 KB |
testcase_10 | AC | 142 ms
54,040 KB |
testcase_11 | AC | 140 ms
54,528 KB |
testcase_12 | WA | - |
testcase_13 | AC | 136 ms
54,288 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 198 ms
56,736 KB |
testcase_18 | AC | 194 ms
54,332 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 118 ms
54,076 KB |
testcase_26 | AC | 117 ms
54,008 KB |
testcase_27 | AC | 108 ms
52,812 KB |
testcase_28 | AC | 124 ms
53,128 KB |
testcase_29 | AC | 119 ms
54,000 KB |
ソースコード
import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); ArrayList<HashMap<Integer, Integer>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(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.get(a).containsKey(b) || graph.get(a).get(b) < c) { graph.get(a).put(b, c); graph.get(b).put(a, c); } } PriorityQueue<Path> queue = new PriorityQueue<>(); int[] costs = new int[n]; int max = 0; for (int i = 0; i < n; i++) { queue.add(new Path(i, 0)); getCost(costs, queue, graph); for (int x : costs) { max = Math.max(max, x); } } System.out.println(max); } static void getCost(int[] costs, PriorityQueue<Path> queue, ArrayList<HashMap<Integer, Integer>> graph) { Arrays.fill(costs, -1); boolean[] used = new boolean[costs.length]; while (queue.size() > 0) { Path p = queue.poll(); if (used[p.idx]) { continue; } used[p.idx] = true; costs[p.idx] = p.value; for (int x : graph.get(p.idx).keySet()) { queue.add(new Path(x, p.value + graph.get(p.idx).get(x))); } } } static class Path implements Comparable<Path> { int idx; int value; public Path(int idx, int value) { this.idx = idx; this.value = value; } public int compareTo(Path another) { return another.value - value; } } }