結果

問題 No.1639 最小通信路
ユーザー irumo8202irumo8202
提出日時 2022-02-13 14:12:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 1,423 bytes
コンパイル時間 455 ms
コンパイル使用メモリ 86,780 KB
実行使用メモリ 79,524 KB
最終ジャッジ日時 2023-09-11 15:28:38
合計ジャッジ時間 7,063 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,436 KB
testcase_01 AC 94 ms
71,216 KB
testcase_02 AC 126 ms
78,092 KB
testcase_03 AC 138 ms
79,524 KB
testcase_04 AC 144 ms
79,404 KB
testcase_05 AC 121 ms
79,312 KB
testcase_06 AC 128 ms
78,956 KB
testcase_07 AC 91 ms
71,724 KB
testcase_08 AC 121 ms
78,364 KB
testcase_09 AC 97 ms
72,056 KB
testcase_10 AC 110 ms
76,716 KB
testcase_11 AC 122 ms
79,040 KB
testcase_12 AC 111 ms
77,508 KB
testcase_13 AC 124 ms
78,164 KB
testcase_14 AC 93 ms
71,532 KB
testcase_15 AC 109 ms
76,852 KB
testcase_16 AC 128 ms
78,924 KB
testcase_17 AC 121 ms
78,464 KB
testcase_18 AC 98 ms
72,144 KB
testcase_19 AC 123 ms
79,128 KB
testcase_20 AC 123 ms
78,472 KB
testcase_21 AC 92 ms
71,380 KB
testcase_22 AC 113 ms
77,424 KB
testcase_23 AC 121 ms
79,196 KB
testcase_24 AC 110 ms
77,532 KB
testcase_25 AC 101 ms
72,028 KB
testcase_26 AC 98 ms
72,208 KB
testcase_27 AC 93 ms
71,384 KB
testcase_28 AC 92 ms
71,452 KB
testcase_29 AC 129 ms
78,532 KB
testcase_30 AC 132 ms
78,288 KB
testcase_31 AC 102 ms
72,152 KB
testcase_32 AC 128 ms
78,284 KB
testcase_33 AC 101 ms
72,260 KB
testcase_34 AC 126 ms
78,444 KB
testcase_35 AC 132 ms
78,200 KB
testcase_36 AC 133 ms
78,320 KB
testcase_37 AC 130 ms
78,336 KB
testcase_38 AC 94 ms
71,276 KB
testcase_39 AC 101 ms
72,452 KB
testcase_40 AC 92 ms
71,500 KB
testcase_41 AC 99 ms
72,252 KB
testcase_42 AC 127 ms
78,164 KB
testcase_43 AC 98 ms
72,388 KB
testcase_44 AC 94 ms
71,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N*(N-1)//2)]

from collections import defaultdict


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        group_members = defaultdict(list)
        for member in range(self.n):
            group_members[self.find(member)].append(member)
        return group_members


uf = UnionFind(N+1)
for a, b, c in ABC:
    if uf.same(a, b):
        continue
    uf.union(a, b)
    if uf.size(1) ==N:
        print(c)
        exit()
0