結果
問題 | No.2910 単体ホモロジー入門 |
ユーザー | nikoro256 |
提出日時 | 2024-10-04 22:27:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 44 ms / 2,000 ms |
コード長 | 1,761 bytes |
コンパイル時間 | 172 ms |
コンパイル使用メモリ | 82,144 KB |
実行使用メモリ | 56,312 KB |
最終ジャッジ日時 | 2024-10-04 22:27:55 |
合計ジャッジ時間 | 3,585 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
54,852 KB |
testcase_01 | AC | 39 ms
54,040 KB |
testcase_02 | AC | 39 ms
54,496 KB |
testcase_03 | AC | 39 ms
55,624 KB |
testcase_04 | AC | 41 ms
54,288 KB |
testcase_05 | AC | 38 ms
54,592 KB |
testcase_06 | AC | 39 ms
54,216 KB |
testcase_07 | AC | 40 ms
53,956 KB |
testcase_08 | AC | 40 ms
54,132 KB |
testcase_09 | AC | 40 ms
55,284 KB |
testcase_10 | AC | 38 ms
54,784 KB |
testcase_11 | AC | 39 ms
54,276 KB |
testcase_12 | AC | 39 ms
54,336 KB |
testcase_13 | AC | 39 ms
54,484 KB |
testcase_14 | AC | 43 ms
55,252 KB |
testcase_15 | AC | 41 ms
54,256 KB |
testcase_16 | AC | 37 ms
55,120 KB |
testcase_17 | AC | 39 ms
54,948 KB |
testcase_18 | AC | 41 ms
55,024 KB |
testcase_19 | AC | 39 ms
55,412 KB |
testcase_20 | AC | 40 ms
53,860 KB |
testcase_21 | AC | 38 ms
55,208 KB |
testcase_22 | AC | 37 ms
55,156 KB |
testcase_23 | AC | 38 ms
54,160 KB |
testcase_24 | AC | 38 ms
53,940 KB |
testcase_25 | AC | 41 ms
56,312 KB |
testcase_26 | AC | 41 ms
55,356 KB |
testcase_27 | AC | 40 ms
54,012 KB |
testcase_28 | AC | 38 ms
54,932 KB |
testcase_29 | AC | 39 ms
55,340 KB |
testcase_30 | AC | 41 ms
54,200 KB |
testcase_31 | AC | 41 ms
54,540 KB |
testcase_32 | AC | 42 ms
55,608 KB |
testcase_33 | AC | 43 ms
54,128 KB |
testcase_34 | AC | 40 ms
54,048 KB |
testcase_35 | AC | 38 ms
54,940 KB |
testcase_36 | AC | 44 ms
54,668 KB |
testcase_37 | AC | 41 ms
53,988 KB |
testcase_38 | AC | 40 ms
54,240 KB |
testcase_39 | AC | 39 ms
54,260 KB |
testcase_40 | AC | 39 ms
54,184 KB |
testcase_41 | AC | 40 ms
55,072 KB |
testcase_42 | AC | 40 ms
54,252 KB |
testcase_43 | AC | 40 ms
55,068 KB |
testcase_44 | AC | 38 ms
55,464 KB |
testcase_45 | AC | 38 ms
54,612 KB |
testcase_46 | AC | 39 ms
54,876 KB |
ソースコード
from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): way=[] while True: if self.parents[x] < 0: break else: way.append(x) x=self.parents[x] for w in way: self.parents[w]=x return 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()) N,M=map(int,input().split()) uf=UnionFind(N) edges=[] for _ in range(M): i,j=map(int,input().split()) edges.append((i,j)) V=set(list(map(int,input().split()))) for a,b in edges: if a in V and b in V: uf.union(a,b) for a,b in edges: if a in V and b in V: continue if uf.same(a,b): print('Yes') exit(0) uf.union(a,b) print('No')