結果

問題 No.1639 最小通信路
ユーザー puznekopuzneko
提出日時 2021-12-02 23:54:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 824 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 76,640 KB
最終ジャッジ日時 2023-09-18 11:08:13
合計ジャッジ時間 5,350 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,288 KB
testcase_01 AC 74 ms
71,076 KB
testcase_02 AC 77 ms
71,468 KB
testcase_03 AC 76 ms
71,244 KB
testcase_04 AC 90 ms
76,640 KB
testcase_05 AC 75 ms
71,420 KB
testcase_06 AC 76 ms
71,200 KB
testcase_07 AC 75 ms
71,152 KB
testcase_08 AC 77 ms
71,276 KB
testcase_09 AC 75 ms
71,240 KB
testcase_10 AC 76 ms
71,456 KB
testcase_11 AC 76 ms
71,060 KB
testcase_12 AC 76 ms
71,440 KB
testcase_13 AC 76 ms
71,276 KB
testcase_14 AC 74 ms
71,276 KB
testcase_15 AC 76 ms
71,540 KB
testcase_16 AC 76 ms
71,380 KB
testcase_17 AC 75 ms
71,020 KB
testcase_18 AC 74 ms
71,544 KB
testcase_19 AC 75 ms
71,384 KB
testcase_20 AC 77 ms
71,448 KB
testcase_21 AC 74 ms
71,336 KB
testcase_22 AC 75 ms
71,272 KB
testcase_23 AC 74 ms
71,424 KB
testcase_24 AC 74 ms
71,192 KB
testcase_25 AC 75 ms
71,168 KB
testcase_26 AC 74 ms
71,152 KB
testcase_27 AC 73 ms
71,536 KB
testcase_28 AC 73 ms
71,020 KB
testcase_29 AC 73 ms
71,280 KB
testcase_30 AC 77 ms
71,076 KB
testcase_31 AC 77 ms
71,264 KB
testcase_32 AC 75 ms
71,264 KB
testcase_33 AC 77 ms
71,540 KB
testcase_34 AC 75 ms
71,536 KB
testcase_35 AC 79 ms
75,288 KB
testcase_36 AC 77 ms
71,028 KB
testcase_37 AC 78 ms
71,336 KB
testcase_38 AC 76 ms
71,452 KB
testcase_39 AC 74 ms
71,520 KB
testcase_40 AC 76 ms
71,352 KB
testcase_41 AC 75 ms
71,448 KB
testcase_42 AC 78 ms
71,152 KB
testcase_43 AC 76 ms
71,380 KB
testcase_44 AC 76 ms
71,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10000000)
n = int(stdin.readline().rstrip())

par = [i for i in range(n+1)]
rank = [0 for i in range(n+1)]

def root(x):
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x])
        return par[x]

def unite(x,y):
    karix = root(x)
    kariy = root(y)
    if karix == kariy:
        return 0
    if rank[karix] < rank[kariy]:
        par[karix] = kariy
    else:
        par[kariy] = karix
        if rank[karix] == rank[kariy]:
            rank[karix] += 1

def same(x,y):
    return root(x) == root(y)

num = 1
for i in range(n*(n-1)//2):
    a, b, c = stdin.readline().rstrip().split()
    a = int(a)
    b = int(b)
    if not same(a,b):
        num += 1
        unite(a,b)
    if num == n:
        print(c)
        exit()
0