結果

問題 No.1639 最小通信路
ユーザー tcltktcltk
提出日時 2021-10-18 03:25:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 305 ms / 2,000 ms
コード長 1,767 bytes
コンパイル時間 962 ms
コンパイル使用メモリ 81,680 KB
実行使用メモリ 90,548 KB
最終ジャッジ日時 2023-10-18 23:15:59
合計ジャッジ時間 13,210 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
87,780 KB
testcase_01 AC 157 ms
88,312 KB
testcase_02 AC 305 ms
90,328 KB
testcase_03 AC 292 ms
90,452 KB
testcase_04 AC 305 ms
90,548 KB
testcase_05 AC 228 ms
89,456 KB
testcase_06 AC 261 ms
89,952 KB
testcase_07 AC 162 ms
88,564 KB
testcase_08 AC 302 ms
90,536 KB
testcase_09 AC 193 ms
88,852 KB
testcase_10 AC 234 ms
89,168 KB
testcase_11 AC 260 ms
89,780 KB
testcase_12 AC 236 ms
89,456 KB
testcase_13 AC 293 ms
90,324 KB
testcase_14 AC 159 ms
88,312 KB
testcase_15 AC 228 ms
88,948 KB
testcase_16 AC 256 ms
89,908 KB
testcase_17 AC 267 ms
90,048 KB
testcase_18 AC 208 ms
88,924 KB
testcase_19 AC 244 ms
89,556 KB
testcase_20 AC 302 ms
90,324 KB
testcase_21 AC 141 ms
87,940 KB
testcase_22 AC 238 ms
89,456 KB
testcase_23 AC 277 ms
89,796 KB
testcase_24 AC 229 ms
88,932 KB
testcase_25 AC 220 ms
88,924 KB
testcase_26 AC 181 ms
88,716 KB
testcase_27 AC 172 ms
88,580 KB
testcase_28 AC 164 ms
88,712 KB
testcase_29 AC 251 ms
89,800 KB
testcase_30 AC 266 ms
89,980 KB
testcase_31 AC 211 ms
89,064 KB
testcase_32 AC 242 ms
89,680 KB
testcase_33 AC 198 ms
88,888 KB
testcase_34 AC 249 ms
89,848 KB
testcase_35 AC 270 ms
90,188 KB
testcase_36 AC 241 ms
89,680 KB
testcase_37 AC 251 ms
89,968 KB
testcase_38 AC 169 ms
88,628 KB
testcase_39 AC 199 ms
89,028 KB
testcase_40 AC 179 ms
88,696 KB
testcase_41 AC 197 ms
88,968 KB
testcase_42 AC 262 ms
89,976 KB
testcase_43 AC 210 ms
88,916 KB
testcase_44 AC 164 ms
88,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """# paste here...
# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**101

class UnionFind():
    parents = []
    sizes = []
    count = 0
    def __init__(self, n):
        self.count = n
        self.parents = [i for i in range(n)]
        self.sizes = [1 for i in range(n)]
    def find(self, i):
        if self.parents[i] == i:
            return i
        else:
            self.parents[i] = self.find(self.parents[i])
            return self.parents[i]
    def unite(self, i, j):
        root_i = self.find(i)
        root_j = self.find(j)
        if root_i == root_j:
            return
        elif root_i < root_j:
            self.parents[root_j] = root_i
            self.sizes[root_i] += self.sizes[root_j]
        else:
            self.parents[root_i] = root_j
            self.sizes[root_j] += self.sizes[root_i]
    def same(self, i, j):
        return self.find(i) == self.find(j)
    def size(self, i):
        return self.sizes[self.find(i)]
    def group_count(self):
        return len(set(self.find(i) for i in range(self.count)))

def check(r):
    uf = UnionFind(N)
    for a, b, c in L:
        if c <= r:
            uf.unite(a, b)
    for i in range(N):
        if not uf.same(i, 0):
            return False
    return True

N = int(input())
L = []
for _ in range(N*(N-1)//2):
    a, b, c = map(int, input().split())
    L.append((a-1, b-1, c))

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