結果

問題 No.1639 最小通信路
ユーザー roarisroaris
提出日時 2021-08-06 22:06:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,218 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 81,808 KB
実行使用メモリ 76,912 KB
最終ジャッジ日時 2023-10-17 03:29:22
合計ジャッジ時間 3,784 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,552 KB
testcase_01 AC 37 ms
53,552 KB
testcase_02 AC 62 ms
76,352 KB
testcase_03 AC 74 ms
76,908 KB
testcase_04 AC 79 ms
76,912 KB
testcase_05 AC 54 ms
66,660 KB
testcase_06 AC 54 ms
68,708 KB
testcase_07 AC 37 ms
53,552 KB
testcase_08 AC 56 ms
72,804 KB
testcase_09 AC 40 ms
58,800 KB
testcase_10 AC 44 ms
61,792 KB
testcase_11 AC 55 ms
70,756 KB
testcase_12 AC 46 ms
61,808 KB
testcase_13 AC 58 ms
74,136 KB
testcase_14 AC 37 ms
53,552 KB
testcase_15 AC 45 ms
61,792 KB
testcase_16 AC 56 ms
70,756 KB
testcase_17 AC 57 ms
72,804 KB
testcase_18 AC 38 ms
53,552 KB
testcase_19 AC 53 ms
66,660 KB
testcase_20 AC 57 ms
72,804 KB
testcase_21 AC 36 ms
53,552 KB
testcase_22 AC 47 ms
63,856 KB
testcase_23 AC 54 ms
68,708 KB
testcase_24 AC 46 ms
61,808 KB
testcase_25 AC 44 ms
61,476 KB
testcase_26 AC 39 ms
53,552 KB
testcase_27 AC 37 ms
53,552 KB
testcase_28 AC 37 ms
53,552 KB
testcase_29 AC 59 ms
68,716 KB
testcase_30 AC 62 ms
72,812 KB
testcase_31 AC 44 ms
59,424 KB
testcase_32 AC 59 ms
70,764 KB
testcase_33 AC 41 ms
58,800 KB
testcase_34 AC 60 ms
70,764 KB
testcase_35 AC 70 ms
76,536 KB
testcase_36 AC 59 ms
68,716 KB
testcase_37 AC 60 ms
70,764 KB
testcase_38 AC 37 ms
53,552 KB
testcase_39 AC 45 ms
61,476 KB
testcase_40 AC 38 ms
53,552 KB
testcase_41 AC 41 ms
58,800 KB
testcase_42 AC 61 ms
72,812 KB
testcase_43 AC 43 ms
58,800 KB
testcase_44 AC 38 ms
53,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class Unionfind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [1]*n
    
    def root(self, x):
        r = x
        
        while not self.par[r]<0:
            r = self.par[r]
        
        t = x
        
        while t!=r:
            tmp = t
            t = self.par[t]
            self.par[tmp] = r
        
        return r
    
    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        
        if rx==ry:
            return
        
        if self.rank[rx]<=self.rank[ry]:
            self.par[ry] += self.par[rx]
            self.par[rx] = ry
            
            if self.rank[rx]==self.rank[ry]:
                self.rank[ry] += 1
        else:
            self.par[rx] += self.par[ry]
            self.par[ry] = rx
    
    def is_same(self, x, y):
        return self.root(x)==self.root(y)
    
    def count(self, x):
        return -self.par[self.root(x)]

N = int(input())
abc = [tuple(map(int, input().split())) for _ in range(N*(N-1)//2)]
abc.sort(key=lambda t: t[2])
uf = Unionfind(N)

for a, b, c in abc:
    if not uf.is_same(a-1, b-1):
        uf.unite(a-1, b-1)
        ans = c

print(ans)
0