結果

問題 No.1639 最小通信路
ユーザー 👑 hitonanodehitonanode
提出日時 2021-08-06 22:14:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 128 ms
コンパイル使用メモリ 11,968 KB
実行使用メモリ 10,916 KB
最終ジャッジ日時 2023-10-17 03:37:40
合計ジャッジ時間 3,053 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,144 KB
testcase_01 AC 28 ms
10,144 KB
testcase_02 AC 45 ms
10,676 KB
testcase_03 AC 49 ms
10,916 KB
testcase_04 AC 52 ms
10,916 KB
testcase_05 AC 32 ms
10,268 KB
testcase_06 AC 36 ms
10,372 KB
testcase_07 AC 30 ms
10,144 KB
testcase_08 AC 41 ms
10,540 KB
testcase_09 AC 30 ms
10,164 KB
testcase_10 AC 32 ms
10,212 KB
testcase_11 AC 38 ms
10,424 KB
testcase_12 AC 32 ms
10,236 KB
testcase_13 AC 45 ms
10,660 KB
testcase_14 AC 29 ms
10,144 KB
testcase_15 AC 32 ms
10,220 KB
testcase_16 AC 38 ms
10,452 KB
testcase_17 AC 41 ms
10,540 KB
testcase_18 AC 30 ms
10,160 KB
testcase_19 AC 34 ms
10,296 KB
testcase_20 AC 41 ms
10,556 KB
testcase_21 AC 29 ms
10,144 KB
testcase_22 AC 33 ms
10,252 KB
testcase_23 AC 36 ms
10,368 KB
testcase_24 AC 32 ms
10,232 KB
testcase_25 AC 31 ms
10,228 KB
testcase_26 AC 31 ms
10,188 KB
testcase_27 AC 29 ms
10,164 KB
testcase_28 AC 29 ms
10,152 KB
testcase_29 AC 35 ms
10,388 KB
testcase_30 AC 39 ms
10,524 KB
testcase_31 AC 31 ms
10,216 KB
testcase_32 AC 36 ms
10,432 KB
testcase_33 AC 30 ms
10,200 KB
testcase_34 AC 35 ms
10,396 KB
testcase_35 AC 43 ms
10,716 KB
testcase_36 AC 34 ms
10,380 KB
testcase_37 AC 36 ms
10,444 KB
testcase_38 AC 30 ms
10,156 KB
testcase_39 AC 32 ms
10,228 KB
testcase_40 AC 29 ms
10,172 KB
testcase_41 AC 30 ms
10,200 KB
testcase_42 AC 39 ms
10,504 KB
testcase_43 AC 31 ms
10,204 KB
testcase_44 AC 30 ms
10,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

CAB = list()
for e in range(N * (N - 1) // 2):
    A, B, C = map(int, input().split())
    CAB.append((C, A - 1, B - 1))

CAB.sort()

class DSU:
    def __init__(self, N: int) -> None:
        self.par = list(range(N))
        self.sz = [1] * N

    def find(self, x: int) -> int:
        if self.par[x] != x:
            self.par[x] = self.find(self.par[x])
        return self.par[x]

    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self.sz[x] < self.sz[y]:
            x, y = y, x
        self.par[y] = x
        self.sz[x] += self.sz[y]
        return True

uf = DSU(N)

for c, a, b in CAB:
    if uf.find(a) != uf.find(b):
        uf.unite(a, b)
        if uf.sz[uf.find(0)] == N:
            print(c)
            exit(0)
0