結果
| 問題 |
No.2912 0次パーシステントホモロジー
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2024-10-04 22:35:58 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,274 ms / 2,000 ms |
| コード長 | 997 bytes |
| コンパイル時間 | 100 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 53,452 KB |
| 最終ジャッジ日時 | 2024-10-04 22:36:12 |
| 合計ジャッジ時間 | 7,810 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
import sys
input = sys.stdin.readline
N,M=map(int,input().split())
# 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)
X=[]
for i in range(M):
x,y,w=map(int,input().split())
X.append([w,x,y])
T=int(input())
R=list(map(int,input().split()))
for i in range(T):
X.append([R[i],10**9,i])
X.sort()
NOW=N
ANS=[0]*T
for w,x,y in X:
if x==10**9:
ANS[y]=NOW
else:
if find(x)!=find(y):
Union(x,y)
NOW-=1
for ans in ANS:
print(ans)
titia