結果

問題 No.1639 最小通信路
ユーザー hir355hir355
提出日時 2021-08-06 21:56:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,046 bytes
コンパイル時間 426 ms
コンパイル使用メモリ 81,796 KB
実行使用メモリ 75,940 KB
最終ジャッジ日時 2023-10-17 03:19:31
合計ジャッジ時間 3,377 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,548 KB
testcase_01 AC 38 ms
53,548 KB
testcase_02 AC 44 ms
55,596 KB
testcase_03 AC 41 ms
53,548 KB
testcase_04 AC 84 ms
75,940 KB
testcase_05 AC 40 ms
53,548 KB
testcase_06 AC 40 ms
53,548 KB
testcase_07 AC 39 ms
53,548 KB
testcase_08 AC 43 ms
55,596 KB
testcase_09 AC 39 ms
53,548 KB
testcase_10 AC 39 ms
53,548 KB
testcase_11 AC 39 ms
53,548 KB
testcase_12 AC 39 ms
53,548 KB
testcase_13 AC 40 ms
53,548 KB
testcase_14 AC 38 ms
53,548 KB
testcase_15 AC 39 ms
53,548 KB
testcase_16 AC 40 ms
53,548 KB
testcase_17 AC 41 ms
53,548 KB
testcase_18 AC 38 ms
53,548 KB
testcase_19 AC 39 ms
53,548 KB
testcase_20 AC 43 ms
55,596 KB
testcase_21 AC 38 ms
53,548 KB
testcase_22 AC 39 ms
53,548 KB
testcase_23 AC 39 ms
53,548 KB
testcase_24 AC 38 ms
53,548 KB
testcase_25 AC 38 ms
53,548 KB
testcase_26 AC 38 ms
53,548 KB
testcase_27 AC 38 ms
53,548 KB
testcase_28 AC 37 ms
53,548 KB
testcase_29 AC 38 ms
53,548 KB
testcase_30 AC 40 ms
53,548 KB
testcase_31 AC 38 ms
53,548 KB
testcase_32 AC 39 ms
53,548 KB
testcase_33 AC 38 ms
53,548 KB
testcase_34 AC 40 ms
53,548 KB
testcase_35 AC 47 ms
61,244 KB
testcase_36 AC 42 ms
55,596 KB
testcase_37 AC 40 ms
53,548 KB
testcase_38 AC 38 ms
53,548 KB
testcase_39 AC 38 ms
53,548 KB
testcase_40 AC 38 ms
53,548 KB
testcase_41 AC 39 ms
53,548 KB
testcase_42 AC 41 ms
53,548 KB
testcase_43 AC 38 ms
53,548 KB
testcase_44 AC 38 ms
53,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n + 1)
        self.size = [1] * (n + 1)
 
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
 
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

n = int(input())
uf = UnionFind(n)
cnt = 0
for i in range(n * (n - 1) // 2):
    a, b, c = map(int, input().split())
    if not uf.same_check(a - 1, b - 1):
        uf.unite(a - 1, b - 1)
        cnt += 1
    if cnt == n - 1:
        print(c)
        break
0