結果

問題 No.1639 最小通信路
ユーザー nephrologistnephrologist
提出日時 2021-08-06 22:04:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,465 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 81,796 KB
実行使用メモリ 78,792 KB
最終ジャッジ日時 2023-10-17 03:26:28
合計ジャッジ時間 6,485 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,616 KB
testcase_01 AC 45 ms
61,328 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 49 ms
61,928 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 39 ms
53,616 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())


class UnionFind:
    # あり本実装
    # rankとrootの配列を1つで賄う方法
    def __init__(self, n):
        self.n = n
        self.par = [-1] * n

    # 根を求める
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 同じかどうかの判定
    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    # 集合の大きさ
    def size(self, x):
        return -self.par[self.find(x)]

    # 2つの集合の合体
    # 重みが大きい方に小さい方をつけるようにする
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False

        if self.par[x] > self.par[y]:
            x, y = y, x
        self.par[x] += self.par[y]
        self.par[y] = x
        return True


num = (n * (n - 1)) // 2
ans = 0

ABC = [list(map(int, input().split())) for _ in range(num)]
ABC.sort(key=lambda x: x[2])

ok = 10 ** 100 + 10
ng = 0


def check(mid):
    UF = UnionFind(n)
    cnt = 1
    for i in range(num):
        a, b, c = ABC[i]
        a, b = a - 1, b - 1
        if c > mid:
            break
        UF.unite(a, b)
        cnt += 1
        if cnt == n:
            return 1
    return 0


while ok - ng > 1:
    mid = (ok + ng) // 2
    if check(mid):
        ok = mid
    else:
        ng = mid

print(ok)
0