結果

問題 No.1639 最小通信路
ユーザー tonyu0tonyu0
提出日時 2022-09-21 18:49:38
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 514 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-12-22 04:17:06
合計ジャッジ時間 3,262 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
a = []
par=[-1]*n

def root(x):
    if par[x] < 0:return x
    return root(par[x])
def same(x,y):
    return root(x)==root(y)
def merge(x, y):
    if same(x,y):return
    x=root(x)
    y=root(y)
    if par[x]>par[y]:
        x,y=y,x
    par[x]+=par[y]
    par[y]=x
def sz(x):
    return -par[root(x)]

for _ in range(n*(n-1)//2):
    x,y,z=map(int,input().split())
    x-=1
    y-=1
    a.append([z, x, y])
a=sorted(a)

for z,x,y in a:
    merge(x, y)
    if sz(0)==n:
        print(z)
        break
0