結果
問題 | No.1473 おでぶなおばけさん |
ユーザー | tenten |
提出日時 | 2022-09-30 13:21:12 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,714 bytes |
コンパイル時間 | 3,034 ms |
コンパイル使用メモリ | 82,348 KB |
実行使用メモリ | 73,092 KB |
最終ジャッジ日時 | 2023-08-24 05:18:50 |
合計ジャッジ時間 | 31,943 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 68 ms
35,044 KB |
testcase_01 | AC | 65 ms
35,164 KB |
testcase_02 | AC | 799 ms
63,860 KB |
testcase_03 | AC | 613 ms
55,672 KB |
testcase_04 | AC | 518 ms
53,420 KB |
testcase_05 | AC | 320 ms
47,124 KB |
testcase_06 | AC | 667 ms
56,604 KB |
testcase_07 | AC | 767 ms
63,928 KB |
testcase_08 | AC | 795 ms
64,216 KB |
testcase_09 | AC | 775 ms
64,020 KB |
testcase_10 | AC | 487 ms
47,248 KB |
testcase_11 | AC | 473 ms
47,948 KB |
testcase_12 | AC | 484 ms
47,660 KB |
testcase_13 | AC | 377 ms
46,312 KB |
testcase_14 | AC | 327 ms
44,848 KB |
testcase_15 | AC | 436 ms
46,524 KB |
testcase_16 | AC | 462 ms
47,212 KB |
testcase_17 | AC | 191 ms
42,340 KB |
testcase_18 | AC | 222 ms
44,072 KB |
testcase_19 | AC | 455 ms
48,484 KB |
testcase_20 | AC | 550 ms
54,164 KB |
testcase_21 | AC | 586 ms
50,744 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 656 ms
59,480 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 656 ms
64,296 KB |
testcase_32 | AC | 534 ms
55,720 KB |
testcase_33 | AC | 531 ms
54,308 KB |
testcase_34 | AC | 395 ms
48,220 KB |
testcase_35 | AC | 366 ms
46,584 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | AC | 470 ms
47,400 KB |
testcase_40 | AC | 466 ms
48,340 KB |
testcase_41 | AC | 447 ms
47,288 KB |
testcase_42 | AC | 444 ms
47,320 KB |
testcase_43 | AC | 538 ms
56,560 KB |
testcase_44 | AC | 537 ms
56,596 KB |
testcase_45 | AC | 530 ms
56,032 KB |
testcase_46 | AC | 640 ms
57,020 KB |
testcase_47 | AC | 671 ms
59,940 KB |
testcase_48 | AC | 635 ms
58,112 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(); Road[] roads = new Road[m]; for (int i = 0; i < m; i++) { roads[i] = new Road(sc.nextInt() - 1, sc.nextInt() - 1, sc.nextInt()); } Arrays.sort(roads); ArrayList<ArrayList<Integer>> graph = new ArrayList<>(); for (int i = 0; i < n; i++) { graph.add(new ArrayList<>()); } UnionFindTree uft = new UnionFindTree(n); int ans = 0; for (Road x : roads) { uft.unite(x); graph.get(x.left).add(x.right); graph.get(x.right).add(x.left); if (uft.same(0, n - 1)) { ans = x.weight; break; } } PriorityQueue<Path> queue = new PriorityQueue<>(); int[] costs = new int[n]; Arrays.fill(costs, Integer.MAX_VALUE); queue.add(new Path(0, 0)); 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(ans + " " + costs[n - 1]); } 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; } } static class Road implements Comparable<Road> { int left; int right; int weight; public Road(int left, int right, int weight) { this.left = left; this.right = right; this.weight = weight; } public int compareTo(Road another) { return another.weight - weight; } } 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 void unite(int x, int y) { if (!same(x, y)) { parents[find(x)] = find(y); } } public void unite(Road r) { unite(r.left, r.right); } } } 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 String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }