結果

問題 No.1639 最小通信路
ユーザー sotanishysotanishy
提出日時 2021-08-06 21:48:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 988 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 81,748 KB
実行使用メモリ 76,716 KB
最終ジャッジ日時 2023-10-17 03:08:14
合計ジャッジ時間 3,681 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,584 KB
testcase_01 AC 37 ms
53,584 KB
testcase_02 AC 56 ms
72,712 KB
testcase_03 AC 71 ms
76,716 KB
testcase_04 AC 70 ms
76,712 KB
testcase_05 AC 52 ms
64,528 KB
testcase_06 AC 53 ms
66,576 KB
testcase_07 AC 38 ms
53,584 KB
testcase_08 AC 54 ms
70,672 KB
testcase_09 AC 37 ms
53,584 KB
testcase_10 AC 43 ms
59,200 KB
testcase_11 AC 55 ms
68,624 KB
testcase_12 AC 45 ms
61,304 KB
testcase_13 AC 55 ms
72,720 KB
testcase_14 AC 37 ms
53,584 KB
testcase_15 AC 43 ms
59,200 KB
testcase_16 AC 55 ms
68,624 KB
testcase_17 AC 55 ms
70,672 KB
testcase_18 AC 37 ms
53,584 KB
testcase_19 AC 54 ms
66,576 KB
testcase_20 AC 54 ms
70,672 KB
testcase_21 AC 37 ms
53,584 KB
testcase_22 AC 46 ms
61,304 KB
testcase_23 AC 53 ms
66,576 KB
testcase_24 AC 45 ms
61,304 KB
testcase_25 AC 40 ms
55,632 KB
testcase_26 AC 38 ms
53,584 KB
testcase_27 AC 38 ms
53,584 KB
testcase_28 AC 37 ms
53,584 KB
testcase_29 AC 55 ms
66,580 KB
testcase_30 AC 60 ms
70,704 KB
testcase_31 AC 39 ms
53,584 KB
testcase_32 AC 56 ms
68,628 KB
testcase_33 AC 38 ms
53,584 KB
testcase_34 AC 56 ms
68,628 KB
testcase_35 AC 60 ms
72,984 KB
testcase_36 AC 54 ms
66,580 KB
testcase_37 AC 57 ms
68,628 KB
testcase_38 AC 37 ms
53,584 KB
testcase_39 AC 41 ms
55,632 KB
testcase_40 AC 37 ms
53,584 KB
testcase_41 AC 38 ms
53,584 KB
testcase_42 AC 58 ms
70,676 KB
testcase_43 AC 39 ms
53,584 KB
testcase_44 AC 38 ms
53,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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

    def find(self, x):
        r = x
        while self.par[r] >= 0:
            r = self.par[r]
        while x != r:
            tmp = self.par[x]
            self.par[x] = r
            x = tmp
        return r

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.par[x] > self.par[y]:
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x

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

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

N = int(input())
edges = []
for _ in range(N*(N-1)//2):
    a, b, C = map(int, input().split())
    a -= 1
    b -= 1
    edges.append((a, b, C))
uf = UnionFind(N)
ans = 0
for u, v, weight in edges:
    if not uf.same(u, v):
        uf.unite(u, v)
        ans = max(ans, weight)
print(ans)
0