結果

問題 No.1639 最小通信路
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-08-07 12:28:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 11,972 KB
実行使用メモリ 10,248 KB
最終ジャッジ日時 2023-10-17 18:58:27
合計ジャッジ時間 3,115 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,232 KB
testcase_01 AC 30 ms
10,232 KB
testcase_02 AC 31 ms
10,240 KB
testcase_03 AC 32 ms
10,248 KB
testcase_04 AC 50 ms
10,248 KB
testcase_05 AC 31 ms
10,240 KB
testcase_06 AC 32 ms
10,240 KB
testcase_07 AC 31 ms
10,232 KB
testcase_08 AC 32 ms
10,240 KB
testcase_09 AC 33 ms
10,232 KB
testcase_10 AC 32 ms
10,240 KB
testcase_11 AC 32 ms
10,240 KB
testcase_12 AC 31 ms
10,240 KB
testcase_13 AC 33 ms
10,240 KB
testcase_14 AC 31 ms
10,232 KB
testcase_15 AC 32 ms
10,240 KB
testcase_16 AC 33 ms
10,240 KB
testcase_17 AC 30 ms
10,240 KB
testcase_18 AC 29 ms
10,232 KB
testcase_19 AC 29 ms
10,240 KB
testcase_20 AC 30 ms
10,240 KB
testcase_21 AC 29 ms
10,232 KB
testcase_22 AC 30 ms
10,240 KB
testcase_23 AC 30 ms
10,240 KB
testcase_24 AC 30 ms
10,240 KB
testcase_25 AC 30 ms
10,240 KB
testcase_26 AC 29 ms
10,240 KB
testcase_27 AC 29 ms
10,232 KB
testcase_28 AC 30 ms
10,232 KB
testcase_29 AC 30 ms
10,240 KB
testcase_30 AC 30 ms
10,248 KB
testcase_31 AC 29 ms
10,240 KB
testcase_32 AC 30 ms
10,248 KB
testcase_33 AC 30 ms
10,240 KB
testcase_34 AC 30 ms
10,248 KB
testcase_35 AC 31 ms
10,248 KB
testcase_36 AC 30 ms
10,248 KB
testcase_37 AC 30 ms
10,248 KB
testcase_38 AC 30 ms
10,232 KB
testcase_39 AC 30 ms
10,240 KB
testcase_40 AC 29 ms
10,240 KB
testcase_41 AC 29 ms
10,240 KB
testcase_42 AC 30 ms
10,248 KB
testcase_43 AC 29 ms
10,240 KB
testcase_44 AC 30 ms
10,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#Union-Find
class UnionFind():
    def __init__(self, n: int) -> None:
        self.n = n
        self.par = list(range(self.n))
        self.rank = [1] * self.n
        self._count = self.n

    def find(self, x: int) -> int:
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x: int, y: int) -> None:
        p = self.find(x)
        q = self.find(y)
        if p == q:
            return None
        if p > q:
            p, q = q, p
        self.rank[p] += self.rank[q]
        self.par[q] = p
        self._count -= 1

    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)

    def size(self, x: int) -> int:
        return self.rank[x]

    def count(self) -> int:
        return self._count

n = int(input())
UF = UnionFind(n)
for _ in range(n * (n - 1) // 2):
    a, b, c = map(int, input().split())
    UF.unite(a - 1, b - 1)
    if UF.count() == 1: exit(print(c))
0