結果

問題 No.1639 最小通信路
ユーザー hir355hir355
提出日時 2021-08-06 21:56:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 1,046 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 82,160 KB
実行使用メモリ 76,188 KB
最終ジャッジ日時 2024-09-17 01:55:07
合計ジャッジ時間 3,544 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,888 KB
testcase_01 AC 39 ms
52,976 KB
testcase_02 AC 44 ms
54,724 KB
testcase_03 AC 42 ms
54,760 KB
testcase_04 AC 84 ms
76,188 KB
testcase_05 AC 39 ms
53,216 KB
testcase_06 AC 41 ms
53,488 KB
testcase_07 AC 38 ms
52,356 KB
testcase_08 AC 43 ms
53,688 KB
testcase_09 AC 40 ms
53,200 KB
testcase_10 AC 39 ms
53,160 KB
testcase_11 AC 40 ms
52,972 KB
testcase_12 AC 40 ms
53,308 KB
testcase_13 AC 42 ms
54,140 KB
testcase_14 AC 38 ms
53,024 KB
testcase_15 AC 39 ms
52,484 KB
testcase_16 AC 42 ms
53,768 KB
testcase_17 AC 43 ms
54,248 KB
testcase_18 AC 40 ms
54,220 KB
testcase_19 AC 41 ms
53,616 KB
testcase_20 AC 43 ms
54,792 KB
testcase_21 AC 37 ms
52,824 KB
testcase_22 AC 40 ms
52,788 KB
testcase_23 AC 41 ms
53,548 KB
testcase_24 AC 40 ms
53,076 KB
testcase_25 AC 40 ms
53,304 KB
testcase_26 AC 40 ms
52,888 KB
testcase_27 AC 40 ms
53,528 KB
testcase_28 AC 38 ms
52,924 KB
testcase_29 AC 39 ms
53,084 KB
testcase_30 AC 42 ms
54,668 KB
testcase_31 AC 39 ms
52,556 KB
testcase_32 AC 41 ms
53,684 KB
testcase_33 AC 40 ms
53,812 KB
testcase_34 AC 41 ms
54,056 KB
testcase_35 AC 48 ms
61,184 KB
testcase_36 AC 43 ms
55,020 KB
testcase_37 AC 41 ms
53,284 KB
testcase_38 AC 39 ms
52,772 KB
testcase_39 AC 41 ms
53,832 KB
testcase_40 AC 38 ms
52,708 KB
testcase_41 AC 38 ms
53,168 KB
testcase_42 AC 41 ms
53,680 KB
testcase_43 AC 40 ms
53,788 KB
testcase_44 AC 40 ms
53,616 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