結果

問題 No.3087 University Coloring
ユーザー moon17
提出日時 2025-04-04 22:09:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 634 ms / 2,000 ms
コード長 346 bytes
コンパイル時間 567 ms
コンパイル使用メモリ 82,336 KB
実行使用メモリ 104,576 KB
最終ジャッジ日時 2025-04-04 22:10:19
合計ジャッジ時間 19,538 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())
abc=[[*map(int,input().split())]for _ in range(m)]
abc.sort(key=lambda x:-x[2])
uf=[*range(n)]
def find(x):
 q=[]
 while uf[x]^x:q+=x,;x=uf[x]
 for p in q:uf[p]=x
 return x
def unite(x,y):
 x,y=find(x),find(y)
 if x^y:uf[x]=y
s=0
for a,b,c in abc:
  a-=1;b-=1
  if find(a)!=find(b):
    unite(a,b)
    s+=c
print(s*2)
0