結果

問題 No.1639 最小通信路
ユーザー titiatitia
提出日時 2021-08-06 21:43:11
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 11,916 KB
実行使用メモリ 10,124 KB
最終ジャッジ日時 2023-10-17 03:00:47
合計ジャッジ時間 3,053 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,108 KB
testcase_01 AC 27 ms
10,108 KB
testcase_02 AC 35 ms
10,124 KB
testcase_03 AC 37 ms
10,124 KB
testcase_04 AC 37 ms
10,124 KB
testcase_05 AC 28 ms
10,124 KB
testcase_06 AC 30 ms
10,124 KB
testcase_07 AC 27 ms
10,108 KB
testcase_08 AC 32 ms
10,124 KB
testcase_09 AC 28 ms
10,108 KB
testcase_10 AC 27 ms
10,116 KB
testcase_11 AC 31 ms
10,124 KB
testcase_12 AC 29 ms
10,120 KB
testcase_13 AC 34 ms
10,124 KB
testcase_14 AC 30 ms
10,108 KB
testcase_15 AC 28 ms
10,116 KB
testcase_16 AC 31 ms
10,124 KB
testcase_17 AC 33 ms
10,124 KB
testcase_18 AC 27 ms
10,108 KB
testcase_19 AC 29 ms
10,124 KB
testcase_20 AC 33 ms
10,124 KB
testcase_21 AC 27 ms
10,108 KB
testcase_22 AC 28 ms
10,124 KB
testcase_23 AC 30 ms
10,124 KB
testcase_24 AC 28 ms
10,120 KB
testcase_25 AC 28 ms
10,124 KB
testcase_26 AC 27 ms
10,124 KB
testcase_27 AC 27 ms
10,116 KB
testcase_28 AC 27 ms
10,108 KB
testcase_29 AC 30 ms
10,124 KB
testcase_30 AC 32 ms
10,124 KB
testcase_31 AC 28 ms
10,124 KB
testcase_32 AC 31 ms
10,124 KB
testcase_33 AC 27 ms
10,124 KB
testcase_34 AC 30 ms
10,124 KB
testcase_35 AC 34 ms
10,124 KB
testcase_36 AC 31 ms
10,124 KB
testcase_37 AC 31 ms
10,124 KB
testcase_38 AC 28 ms
10,108 KB
testcase_39 AC 29 ms
10,124 KB
testcase_40 AC 28 ms
10,116 KB
testcase_41 AC 28 ms
10,124 KB
testcase_42 AC 32 ms
10,124 KB
testcase_43 AC 28 ms
10,124 KB
testcase_44 AC 27 ms
10,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
# UnionFind

Group = [i for i in range(N+1)] # グループ分け
Nodes = [1]*(N+1) # 各グループのノードの数

def find(x):
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):
    if find(x) != find(y):
        if Nodes[find(x)] < Nodes[find(y)]:
            
            Nodes[find(y)] += Nodes[find(x)]
            Nodes[find(x)] = 0
            Group[find(x)] = find(y)
            
        else:
            Nodes[find(x)] += Nodes[find(y)]
            Nodes[find(y)] = 0
            Group[find(y)] = find(x)

ANS=0

for i in range(N*(N-1)//2):
    a,b,c=map(int,input().split())

    if find(a)!=find(b):
        Union(a,b)
        ANS=c

print(ANS)
0