結果
問題 | No.1639 最小通信路 |
ユーザー | tenten |
提出日時 | 2021-08-10 08:57:21 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 160 ms / 2,000 ms |
コード長 | 1,852 bytes |
コンパイル時間 | 2,380 ms |
コンパイル使用メモリ | 77,580 KB |
実行使用メモリ | 58,360 KB |
最終ジャッジ日時 | 2023-10-23 15:01:00 |
合計ジャッジ時間 | 9,514 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
52,408 KB |
testcase_01 | AC | 54 ms
53,524 KB |
testcase_02 | AC | 132 ms
55,960 KB |
testcase_03 | AC | 160 ms
58,236 KB |
testcase_04 | AC | 157 ms
58,360 KB |
testcase_05 | AC | 83 ms
54,392 KB |
testcase_06 | AC | 112 ms
55,660 KB |
testcase_07 | AC | 53 ms
53,528 KB |
testcase_08 | AC | 126 ms
55,716 KB |
testcase_09 | AC | 59 ms
53,552 KB |
testcase_10 | AC | 75 ms
54,404 KB |
testcase_11 | AC | 119 ms
55,496 KB |
testcase_12 | AC | 90 ms
54,392 KB |
testcase_13 | AC | 132 ms
56,076 KB |
testcase_14 | AC | 54 ms
53,524 KB |
testcase_15 | AC | 75 ms
54,396 KB |
testcase_16 | AC | 119 ms
56,028 KB |
testcase_17 | AC | 116 ms
55,884 KB |
testcase_18 | AC | 59 ms
53,552 KB |
testcase_19 | AC | 103 ms
55,332 KB |
testcase_20 | AC | 125 ms
56,104 KB |
testcase_21 | AC | 54 ms
53,516 KB |
testcase_22 | AC | 80 ms
54,404 KB |
testcase_23 | AC | 114 ms
55,564 KB |
testcase_24 | AC | 89 ms
54,392 KB |
testcase_25 | AC | 92 ms
54,864 KB |
testcase_26 | AC | 80 ms
54,360 KB |
testcase_27 | AC | 57 ms
53,524 KB |
testcase_28 | AC | 55 ms
53,536 KB |
testcase_29 | AC | 121 ms
55,672 KB |
testcase_30 | AC | 131 ms
56,284 KB |
testcase_31 | AC | 83 ms
54,540 KB |
testcase_32 | AC | 124 ms
55,672 KB |
testcase_33 | AC | 77 ms
54,368 KB |
testcase_34 | AC | 123 ms
55,812 KB |
testcase_35 | AC | 132 ms
56,504 KB |
testcase_36 | AC | 126 ms
55,508 KB |
testcase_37 | AC | 127 ms
56,140 KB |
testcase_38 | AC | 55 ms
53,528 KB |
testcase_39 | AC | 100 ms
54,388 KB |
testcase_40 | AC | 57 ms
53,540 KB |
testcase_41 | AC | 78 ms
54,372 KB |
testcase_42 | AC | 131 ms
56,412 KB |
testcase_43 | AC | 71 ms
54,372 KB |
testcase_44 | AC | 57 ms
53,484 KB |
ソースコード
import java.io.*; import java.util.*; import java.math.BigInteger; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); UnionFindTree uft = new UnionFindTree(n); String ans = ""; for (int i = 0; i < n * (n - 1) / 2; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; String s = sc.next(); if (!uft.same(a, b)) { uft.unite(a, b); ans = s; } } System.out.println(ans); } 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) { parents[find(x)] = find(y); } } } 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 String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }