結果
問題 |
No.3087 University Coloring
|
ユーザー |
![]() |
提出日時 | 2025-04-05 00:08:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,275 ms / 2,000 ms |
コード長 | 676 bytes |
コンパイル時間 | 1,277 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 117,588 KB |
最終ジャッジ日時 | 2025-04-05 00:08:45 |
合計ジャッジ時間 | 30,808 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
N,M=map(int, input().split()) A=[] for i in range(M): a,b,c=map(int,input().split()) a-=1;b-=1 A.append((c,a,b)) A=sorted(A)[::-1] ans=0 par=[i for i in range(N)] rank=[0]*(N) friend=[0]*N block=[0]*N size=[1]*N def find(x): if par[x]==x: return x else: par[x]=find(par[x]) return par[x] #同じ集合か判定 def same(x,y): return find(x)==find(y) def union(x,y): x=find(x) y=find(y) if x==y: return if rank[x]>rank[y]: par[y]=x size[x]+=size[y] else: par[x]=y size[y]+=size[x] if rank[x]==rank[y]: rank[y]+=1 for c,a,b in A: if find(a)!=find(b): ans+=2*c union(a,b) print(ans)