結果

問題 No.1639 最小通信路
ユーザー raven7959
提出日時 2021-08-17 16:29:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 577 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 82,108 KB
実行使用メモリ 76,952 KB
最終ジャッジ日時 2024-10-10 14:55:17
合計ジャッジ時間 4,983 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
E=[]
for i in range(N*(N-1)//2):
  a,b,c=map(int,input().split())
  E.append((c,a-1,b-1))
par=[i for i in range(N)]
rank=[0]*(N+1)
def root(x):
  if par[x]==x:
    return x
  else:
    par[x]=root(par[x])
    return par[x]
def unite(x,y):
  rx,ry=root(x),root(y)
  if rx==ry:
    return
  else:
    if rank[x]<rank[y]:
      par[rx]=ry
    else:
      par[ry]=rx
      if rank[x]==rank[y]:
        rank[x]+=1
def same(x,y):
  rx,ry=root(x),root(y)
  return rx==ry
max_cost=0
for cost,s,g in E:
  if not same(s,g):
    max_cost=cost
    unite(s,g)
print(max_cost)
0