結果
問題 | No.2912 0次パーシステントホモロジー |
ユーザー | tassei903 |
提出日時 | 2024-10-04 21:30:36 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 607 ms / 2,000 ms |
コード長 | 2,121 bytes |
コンパイル時間 | 348 ms |
コンパイル使用メモリ | 82,268 KB |
実行使用メモリ | 105,216 KB |
最終ジャッジ日時 | 2024-10-04 21:30:42 |
合計ジャッジ時間 | 6,057 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
62,336 KB |
testcase_01 | AC | 52 ms
62,336 KB |
testcase_02 | AC | 53 ms
62,592 KB |
testcase_03 | AC | 59 ms
62,592 KB |
testcase_04 | AC | 53 ms
62,720 KB |
testcase_05 | AC | 55 ms
63,336 KB |
testcase_06 | AC | 56 ms
63,616 KB |
testcase_07 | AC | 52 ms
62,336 KB |
testcase_08 | AC | 54 ms
62,208 KB |
testcase_09 | AC | 52 ms
62,080 KB |
testcase_10 | AC | 52 ms
62,200 KB |
testcase_11 | AC | 55 ms
63,616 KB |
testcase_12 | AC | 52 ms
62,336 KB |
testcase_13 | AC | 52 ms
62,720 KB |
testcase_14 | AC | 54 ms
63,232 KB |
testcase_15 | AC | 83 ms
75,372 KB |
testcase_16 | AC | 243 ms
98,176 KB |
testcase_17 | AC | 301 ms
88,320 KB |
testcase_18 | AC | 429 ms
91,312 KB |
testcase_19 | AC | 551 ms
105,088 KB |
testcase_20 | AC | 607 ms
105,216 KB |
testcase_21 | AC | 475 ms
104,448 KB |
testcase_22 | AC | 447 ms
104,448 KB |
ソースコード
import sys #input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): group_members = defaultdict(list) for member in range(self.n): group_members[self.find(member)].append(member) return group_members def __str__(self): return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items()) F = 10 ** 5 + 10 n, m = na() eve = [[] for i in range(F)] for _ in range(m): a, b, c = na() eve[c].append((a, b)) uf = UnionFind(n) ans = n now = 0 T = ni() r = na() idx = sorted(range(T), key=lambda x: r[x]) for i in range(T): while now < r[idx[i]]: now += 1 for a, b in eve[now]: if not uf.same(a, b): ans -= 1 uf.union(a, b) r[idx[i]] = ans for i in range(T): print(r[i])