結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | tenten |
提出日時 | 2022-08-05 09:28:18 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 838 ms / 2,000 ms |
コード長 | 3,882 bytes |
コンパイル時間 | 2,561 ms |
コンパイル使用メモリ | 88,048 KB |
実行使用メモリ | 66,800 KB |
最終ジャッジ日時 | 2024-09-15 05:06:05 |
合計ジャッジ時間 | 32,237 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 82 ms
37,924 KB |
testcase_01 | AC | 86 ms
38,044 KB |
testcase_02 | AC | 793 ms
65,744 KB |
testcase_03 | AC | 636 ms
57,980 KB |
testcase_04 | AC | 539 ms
55,140 KB |
testcase_05 | AC | 344 ms
48,640 KB |
testcase_06 | AC | 695 ms
58,376 KB |
testcase_07 | AC | 812 ms
66,068 KB |
testcase_08 | AC | 838 ms
65,892 KB |
testcase_09 | AC | 820 ms
66,336 KB |
testcase_10 | AC | 504 ms
50,964 KB |
testcase_11 | AC | 532 ms
50,152 KB |
testcase_12 | AC | 513 ms
50,248 KB |
testcase_13 | AC | 413 ms
48,896 KB |
testcase_14 | AC | 347 ms
48,760 KB |
testcase_15 | AC | 453 ms
50,124 KB |
testcase_16 | AC | 484 ms
50,780 KB |
testcase_17 | AC | 204 ms
45,068 KB |
testcase_18 | AC | 239 ms
47,156 KB |
testcase_19 | AC | 474 ms
50,856 KB |
testcase_20 | AC | 571 ms
56,316 KB |
testcase_21 | AC | 614 ms
53,956 KB |
testcase_22 | AC | 613 ms
63,260 KB |
testcase_23 | AC | 582 ms
59,704 KB |
testcase_24 | AC | 589 ms
58,428 KB |
testcase_25 | AC | 624 ms
63,116 KB |
testcase_26 | AC | 646 ms
61,536 KB |
testcase_27 | AC | 401 ms
50,632 KB |
testcase_28 | AC | 734 ms
61,636 KB |
testcase_29 | AC | 486 ms
52,828 KB |
testcase_30 | AC | 560 ms
54,836 KB |
testcase_31 | AC | 672 ms
66,800 KB |
testcase_32 | AC | 545 ms
57,324 KB |
testcase_33 | AC | 509 ms
56,368 KB |
testcase_34 | AC | 394 ms
51,920 KB |
testcase_35 | AC | 371 ms
49,352 KB |
testcase_36 | AC | 549 ms
56,380 KB |
testcase_37 | AC | 599 ms
57,936 KB |
testcase_38 | AC | 295 ms
49,056 KB |
testcase_39 | AC | 485 ms
50,484 KB |
testcase_40 | AC | 474 ms
50,628 KB |
testcase_41 | AC | 485 ms
50,444 KB |
testcase_42 | AC | 478 ms
49,748 KB |
testcase_43 | AC | 558 ms
58,532 KB |
testcase_44 | AC | 536 ms
58,752 KB |
testcase_45 | AC | 558 ms
58,248 KB |
testcase_46 | AC | 632 ms
58,968 KB |
testcase_47 | AC | 694 ms
62,028 KB |
testcase_48 | AC | 675 ms
59,452 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); Bridge[] bridges = new Bridge[m]; for (int i = 0; i < m; i++) { bridges[i] = new Bridge(sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt()); } Arrays.sort(bridges); UnionFindTree uft = new UnionFindTree(n); int max = 0; for (Bridge x : bridges) { uft.unite(x); if (uft.same(0, n - 1)) { max = x.value; break; } } ArrayList<ArrayList<Integer>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } for (Bridge x : bridges) { if (x.value >= max) { graph.get(x.left).add(x.right); graph.get(x.right).add(x.left); } } PriorityQueue<Path> queue = new PriorityQueue<>(); queue.add(new Path(0, 0)); int[] costs = new int[n]; Arrays.fill(costs, Integer.MAX_VALUE); while (queue.size() > 0) { Path p = queue.poll(); if (costs[p.idx] <= p.value) { continue; } costs[p.idx] = p.value; for (int x : graph.get(p.idx)) { queue.add(new Path(x, p.value + 1)); } } System.out.println(max + " " + costs[n - 1]); } static class UnionFindTree { int[] parents; public UnionFindTree(int size) { parents = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; } } public int find(int x) { if (x == parents[x]) { return x; } else { return parents[x] = find(parents[x]); } } public boolean same(int x, int y) { return find(x) == find(y); } public boolean same(Bridge x) { return same(x.left, x.right); } public void unite(int x, int y) { if (!same(x, y)) { parents[find(x)] = find(y); } } public void unite(Bridge b) { unite(b.left, b.right); } } static class Bridge implements Comparable<Bridge> { int left; int right; int value; public Bridge(int left, int right, int value) { this.left = left; this.right = right; this.value = value; } public int compareTo(Bridge another) { return another.value - value; } } 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 value - another.value; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); 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 String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }