結果

問題 No.1639 最小通信路
ユーザー convexineqconvexineq
提出日時 2021-08-06 21:32:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 1,167 bytes
コンパイル時間 500 ms
コンパイル使用メモリ 81,768 KB
実行使用メモリ 76,776 KB
最終ジャッジ日時 2023-10-17 02:51:09
合計ジャッジ時間 4,420 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,196 KB
testcase_01 AC 37 ms
53,196 KB
testcase_02 AC 109 ms
72,940 KB
testcase_03 AC 84 ms
76,540 KB
testcase_04 AC 93 ms
76,776 KB
testcase_05 AC 64 ms
68,656 KB
testcase_06 AC 65 ms
70,704 KB
testcase_07 AC 37 ms
53,444 KB
testcase_08 AC 66 ms
72,752 KB
testcase_09 AC 40 ms
53,444 KB
testcase_10 AC 50 ms
61,428 KB
testcase_11 AC 64 ms
70,704 KB
testcase_12 AC 53 ms
63,660 KB
testcase_13 AC 66 ms
72,752 KB
testcase_14 AC 37 ms
53,444 KB
testcase_15 AC 51 ms
61,428 KB
testcase_16 AC 65 ms
70,704 KB
testcase_17 AC 67 ms
72,752 KB
testcase_18 AC 40 ms
53,444 KB
testcase_19 AC 64 ms
68,656 KB
testcase_20 AC 67 ms
72,752 KB
testcase_21 AC 37 ms
53,444 KB
testcase_22 AC 55 ms
63,660 KB
testcase_23 AC 65 ms
70,704 KB
testcase_24 AC 53 ms
63,660 KB
testcase_25 AC 44 ms
55,492 KB
testcase_26 AC 40 ms
53,444 KB
testcase_27 AC 37 ms
53,444 KB
testcase_28 AC 37 ms
53,444 KB
testcase_29 AC 69 ms
72,840 KB
testcase_30 AC 73 ms
73,620 KB
testcase_31 AC 43 ms
55,492 KB
testcase_32 AC 70 ms
72,840 KB
testcase_33 AC 41 ms
53,444 KB
testcase_34 AC 71 ms
72,840 KB
testcase_35 AC 84 ms
76,564 KB
testcase_36 AC 70 ms
72,840 KB
testcase_37 AC 71 ms
72,840 KB
testcase_38 AC 38 ms
53,444 KB
testcase_39 AC 44 ms
55,492 KB
testcase_40 AC 38 ms
53,444 KB
testcase_41 AC 41 ms
53,444 KB
testcase_42 AC 72 ms
73,276 KB
testcase_43 AC 41 ms
55,492 KB
testcase_44 AC 37 ms
53,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UnionFind:
    def __init__(self, n):
        self.parent = list(range(n)) #親ノード
        self.size = [1]*n #グループの要素数
 
    def root(self, x): #root(x): xの根ノードを返す.
        while self.parent[x] != x:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x 
 
    def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる
        x, y = self.root(x), self.root(y)
        if x == y: return False
        if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように
        self.size[x] += self.size[y] #xの要素数を更新
        self.parent[y] = x #yをxにつなぐ
        return True
 
    def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue
        return self.root(x) == self.root(y)
        
    def getsize(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]

n = int(input())
abc = [list(map(int,input().split())) for _ in range(n*(n-1)//2)]
UF = UnionFind(n+1)
ans = 0
k = 1
for a,b,c in abc:
    if UF.merge(a,b):
        k += 1
    if k == n: break
print(c)
0