結果

問題 No.1639 最小通信路
ユーザー tktk_snsntktk_snsn
提出日時 2021-08-06 23:40:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,144 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 12,044 KB
実行使用メモリ 12,312 KB
最終ジャッジ日時 2023-10-17 05:35:02
合計ジャッジ時間 3,146 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,168 KB
testcase_01 AC 30 ms
10,168 KB
testcase_02 AC 35 ms
11,740 KB
testcase_03 AC 36 ms
12,312 KB
testcase_04 AC 42 ms
12,312 KB
testcase_05 AC 30 ms
10,544 KB
testcase_06 AC 31 ms
10,864 KB
testcase_07 AC 29 ms
10,172 KB
testcase_08 AC 33 ms
11,428 KB
testcase_09 AC 30 ms
10,244 KB
testcase_10 AC 31 ms
10,380 KB
testcase_11 AC 32 ms
11,048 KB
testcase_12 AC 31 ms
10,460 KB
testcase_13 AC 35 ms
11,740 KB
testcase_14 AC 30 ms
10,168 KB
testcase_15 AC 30 ms
10,404 KB
testcase_16 AC 32 ms
11,128 KB
testcase_17 AC 34 ms
11,428 KB
testcase_18 AC 29 ms
10,228 KB
testcase_19 AC 31 ms
10,632 KB
testcase_20 AC 34 ms
11,212 KB
testcase_21 AC 29 ms
10,168 KB
testcase_22 AC 30 ms
10,496 KB
testcase_23 AC 31 ms
10,844 KB
testcase_24 AC 30 ms
10,444 KB
testcase_25 AC 30 ms
10,352 KB
testcase_26 AC 29 ms
10,244 KB
testcase_27 AC 29 ms
10,184 KB
testcase_28 AC 29 ms
10,168 KB
testcase_29 AC 31 ms
10,796 KB
testcase_30 AC 32 ms
11,200 KB
testcase_31 AC 29 ms
10,328 KB
testcase_32 AC 31 ms
10,920 KB
testcase_33 AC 29 ms
10,272 KB
testcase_34 AC 32 ms
10,820 KB
testcase_35 AC 34 ms
11,740 KB
testcase_36 AC 31 ms
10,772 KB
testcase_37 AC 32 ms
10,972 KB
testcase_38 AC 29 ms
10,180 KB
testcase_39 AC 29 ms
10,368 KB
testcase_40 AC 29 ms
10,212 KB
testcase_41 AC 29 ms
10,272 KB
testcase_42 AC 32 ms
11,140 KB
testcase_43 AC 29 ms
10,288 KB
testcase_44 AC 28 ms
10,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


class UF_tree:
    def __init__(self, n):
        self.root = [-1] * (n + 1)
        self.rank = [0] * (n + 1)

    def find(self, x):
        if self.root[x] < 0:
            return x
        self.root[x] = self.find(self.root[x])
        return self.root[x]

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.rank[x] < self.rank[y]:
            self.root[y] += self.root[x]
            self.root[x] = y
        else:
            self.root[x] += self.root[y]
            self.root[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        return True

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


N = int(input())
U = N * (N - 1) // 2
abc = [input().rstrip().split() for _ in range(U)]
uf = UF_tree(N)
ans = -1
for a, b, c in abc:
    a = int(a) - 1
    b = int(b) - 1
    if uf.unite(a, b):
        ans = c
    if uf.size(0) == N:
        break
print(ans)
0