結果

問題 No.1639 最小通信路
ユーザー ayaoniayaoni
提出日時 2021-08-06 21:49:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,616 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 81,808 KB
実行使用メモリ 73,744 KB
最終ジャッジ日時 2023-10-17 03:08:36
合計ジャッジ時間 3,655 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,620 KB
testcase_01 AC 37 ms
53,620 KB
testcase_02 AC 55 ms
68,680 KB
testcase_03 AC 63 ms
73,448 KB
testcase_04 AC 65 ms
73,744 KB
testcase_05 AC 52 ms
66,632 KB
testcase_06 AC 55 ms
66,632 KB
testcase_07 AC 37 ms
53,620 KB
testcase_08 AC 54 ms
68,680 KB
testcase_09 AC 39 ms
53,620 KB
testcase_10 AC 44 ms
61,272 KB
testcase_11 AC 53 ms
66,632 KB
testcase_12 AC 44 ms
61,252 KB
testcase_13 AC 56 ms
68,680 KB
testcase_14 AC 37 ms
53,620 KB
testcase_15 AC 44 ms
61,252 KB
testcase_16 AC 54 ms
66,632 KB
testcase_17 AC 57 ms
68,700 KB
testcase_18 AC 38 ms
53,620 KB
testcase_19 AC 54 ms
66,632 KB
testcase_20 AC 55 ms
68,680 KB
testcase_21 AC 36 ms
53,620 KB
testcase_22 AC 45 ms
61,252 KB
testcase_23 AC 56 ms
68,700 KB
testcase_24 AC 45 ms
61,252 KB
testcase_25 AC 41 ms
58,976 KB
testcase_26 AC 38 ms
53,620 KB
testcase_27 AC 37 ms
53,620 KB
testcase_28 AC 36 ms
53,620 KB
testcase_29 AC 56 ms
68,684 KB
testcase_30 AC 58 ms
68,684 KB
testcase_31 AC 40 ms
55,668 KB
testcase_32 AC 55 ms
68,684 KB
testcase_33 AC 38 ms
53,620 KB
testcase_34 AC 57 ms
68,684 KB
testcase_35 AC 61 ms
72,780 KB
testcase_36 AC 57 ms
68,684 KB
testcase_37 AC 56 ms
68,684 KB
testcase_38 AC 38 ms
53,620 KB
testcase_39 AC 44 ms
61,252 KB
testcase_40 AC 38 ms
53,620 KB
testcase_41 AC 38 ms
53,620 KB
testcase_42 AC 57 ms
68,684 KB
testcase_43 AC 39 ms
53,620 KB
testcase_44 AC 38 ms
53,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


class Kruskal:
    def __init__(self,n):
        self.e = []
        self.par = [i for i in range(n+1)]  # 親のノード番号
        self.rank = [0]*(n+1)

    def add(self,u,v,d):  # クラスカル法で考えるのは無向グラフ(1-index)
        self.e.append((d,u,v))

    def find(self,x):  # xの根のノード番号
        if self.par[x] == x:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def same_check(self,x,y):  # x,yが同じグループか否か
        return self.find(x) == self.find(y)

    def unite(self,x,y):  # x,yの属するグループの併合
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            x,y = y,x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        self.par[y] = x

    def MST(self):
        self.e.sort()
        res = 0
        for d,u,v in self.e:
            if not self.same_check(u,v):
                self.unite(u,v)
                res = max(res,d)
        return res


N = I()
K = Kruskal(N)
for _ in range(N*(N-1)//2):
    a,b,C = MI()
    K.add(a,b,C)

ans = K.MST()
print(ans)
0