結果

問題 No.1639 最小通信路
ユーザー 👑 tamatotamato
提出日時 2021-08-06 21:37:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,383 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 81,996 KB
実行使用メモリ 77,004 KB
最終ジャッジ日時 2023-10-17 02:54:48
合計ジャッジ時間 3,514 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,764 KB
testcase_01 AC 36 ms
53,764 KB
testcase_02 AC 49 ms
68,764 KB
testcase_03 AC 58 ms
73,156 KB
testcase_04 AC 73 ms
77,004 KB
testcase_05 AC 46 ms
62,616 KB
testcase_06 AC 47 ms
64,664 KB
testcase_07 AC 35 ms
53,764 KB
testcase_08 AC 49 ms
66,716 KB
testcase_09 AC 40 ms
59,012 KB
testcase_10 AC 42 ms
59,632 KB
testcase_11 AC 47 ms
64,664 KB
testcase_12 AC 42 ms
61,680 KB
testcase_13 AC 48 ms
68,760 KB
testcase_14 AC 36 ms
53,764 KB
testcase_15 AC 42 ms
61,680 KB
testcase_16 AC 46 ms
64,664 KB
testcase_17 AC 48 ms
66,712 KB
testcase_18 AC 37 ms
53,764 KB
testcase_19 AC 47 ms
64,664 KB
testcase_20 AC 49 ms
66,724 KB
testcase_21 AC 36 ms
53,764 KB
testcase_22 AC 44 ms
61,680 KB
testcase_23 AC 45 ms
64,664 KB
testcase_24 AC 41 ms
61,680 KB
testcase_25 AC 41 ms
61,684 KB
testcase_26 AC 35 ms
53,764 KB
testcase_27 AC 34 ms
53,764 KB
testcase_28 AC 34 ms
53,764 KB
testcase_29 AC 48 ms
66,724 KB
testcase_30 AC 50 ms
68,772 KB
testcase_31 AC 40 ms
59,632 KB
testcase_32 AC 49 ms
66,724 KB
testcase_33 AC 38 ms
59,012 KB
testcase_34 AC 49 ms
66,724 KB
testcase_35 AC 55 ms
72,880 KB
testcase_36 AC 50 ms
66,732 KB
testcase_37 AC 49 ms
66,724 KB
testcase_38 AC 35 ms
53,764 KB
testcase_39 AC 41 ms
61,684 KB
testcase_40 AC 35 ms
53,764 KB
testcase_41 AC 37 ms
59,012 KB
testcase_42 AC 50 ms
68,772 KB
testcase_43 AC 39 ms
59,012 KB
testcase_44 AC 34 ms
53,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    class UnionFind():
        def __init__(self, n):
            self.n = n
            self.root = [-1] * (n + 1)
            self.rnk = [0] * (n + 1)

        def find_root(self, x):
            while self.root[x] >= 0:
                x = self.root[x]
            return x

        def unite(self, x, y):
            x = self.find_root(x)
            y = self.find_root(y)
            if x == y:
                return
            elif self.rnk[x] > self.rnk[y]:
                self.root[x] += self.root[y]
                self.root[y] = x
            else:
                self.root[y] += self.root[x]
                self.root[x] = y
                if self.rnk[x] == self.rnk[y]:
                    self.rnk[y] += 1

        def isSameGroup(self, x, y):
            return self.find_root(x) == self.find_root(y)

        def size(self, x):
            return -self.root[self.find_root(x)]

    N = int(input())
    UF = UnionFind(N)
    E = []
    for _ in range(N * (N-1) // 2):
        E.append(tuple(map(int, input().split())))
    E.sort(key=lambda x: x[2])
    cnt = 0
    for a, b, c in E:
        if not UF.isSameGroup(a, b):
            cnt += 1
            UF.unite(a, b)
        if cnt == N-1:
            print(c)
            break


if __name__ == '__main__':
    main()
0