結果
問題 | No.2912 0次パーシステントホモロジー |
ユーザー |
|
提出日時 | 2024-10-04 22:55:30 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 856 ms / 2,000 ms |
コード長 | 1,685 bytes |
コンパイル時間 | 183 ms |
コンパイル使用メモリ | 81,980 KB |
実行使用メモリ | 109,868 KB |
最終ジャッジ日時 | 2024-10-04 22:55:37 |
合計ジャッジ時間 | 6,661 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
class UnionFind:def __init__(self, n, w=None):self.par = [-1]*nself.rank = [0]*nself.siz = [1]*nself.cnt = nself.min_node = [i for i in range(n)]self.weight = w if w else [1]*ndef root(self, x):if self.par[x] == -1:return xself.par[x] = self.root(self.par[x])return self.par[x]def issame(self, x, y):return self.root(x) == self.root(y)def unite(self, x, y):px = self.root(x)py = self.root(y)if px == py:return Falseif self.rank[px] < self.rank[py]:px, py = py, pxself.par[py] = pxif self.rank[px] == self.rank[py]:self.rank[px] += 1self.siz[px] += self.siz[py]self.cnt -= 1self.min_node[px] = min(self.min_node[px], self.min_node[py])self.weight[px] += self.weight[py]return Falsedef count(self):return self.cntdef min(self, x):return self.min_node[self.root(x)]def getweight(self, x):return self.weight[self.root(x)]def size(self, x):return self.siz[self.root(x)]import sysinput = sys.stdin.readlineN, M = map(int, input().split())IJW = [list(map(int, input().split())) for _ in range(M)]T = int(input())R = list(map(int, input().split()))ans = [0 for _ in range(T)]for i in range(T):r = R[i]R[i] = [r, i]R.sort()IJW.sort(key=lambda x:x[2])UF = UnionFind(N)j = 0for r, i in R:while j<M and IJW[j][2]<=r:u, v, _ = IJW[j]UF.unite(u, v)j+=1ans[i] = UF.count()for a in ans:print(a)