結果
問題 | No.2948 move move rotti |
ユーザー | nikoro256 |
提出日時 | 2024-10-25 21:40:00 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,350 bytes |
コンパイル時間 | 208 ms |
コンパイル使用メモリ | 82,320 KB |
実行使用メモリ | 56,836 KB |
最終ジャッジ日時 | 2024-10-25 21:40:06 |
合計ジャッジ時間 | 2,464 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
54,928 KB |
testcase_01 | AC | 44 ms
55,036 KB |
testcase_02 | AC | 43 ms
55,040 KB |
testcase_03 | AC | 43 ms
56,196 KB |
testcase_04 | AC | 41 ms
55,892 KB |
testcase_05 | AC | 41 ms
55,460 KB |
testcase_06 | WA | - |
testcase_07 | AC | 41 ms
55,676 KB |
testcase_08 | WA | - |
testcase_09 | AC | 43 ms
56,836 KB |
testcase_10 | WA | - |
testcase_11 | AC | 41 ms
55,544 KB |
testcase_12 | AC | 42 ms
55,992 KB |
testcase_13 | AC | 42 ms
54,728 KB |
testcase_14 | AC | 41 ms
54,732 KB |
testcase_15 | AC | 42 ms
55,740 KB |
testcase_16 | AC | 43 ms
55,728 KB |
testcase_17 | AC | 42 ms
55,340 KB |
testcase_18 | AC | 41 ms
55,496 KB |
testcase_19 | AC | 41 ms
55,060 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 43 ms
54,648 KB |
testcase_25 | WA | - |
testcase_26 | AC | 41 ms
54,852 KB |
testcase_27 | AC | 41 ms
56,292 KB |
testcase_28 | AC | 42 ms
56,220 KB |
testcase_29 | AC | 41 ms
54,520 KB |
testcase_30 | AC | 42 ms
56,080 KB |
ソースコード
from collections import deque def bfs(s): dq = deque() dq.append([s, 0]) high = [10**9 for _ in range(N)] high[s] = 0 while len(dq) != 0: p, h = dq.popleft() for e in edge[p]: if high[e] == 10**9: dq.append([e, h + 1]) high[e] = h + 1 return high 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,K=map(int,input().split()) X=list(map(int,input().split())) edge=[[] for _ in range(N)] uf=UnionFind(N) for _ in range(M): u,v=map(int,input().split()) edge[u-1].append(v-1) edge[v-1].append(u-1) uf.union(u-1,v-1) for i in range(K): if not uf.same(X[i]-1,X[0]-1): print('No') exit(0) #連結か? dist=[b%2 for b in bfs(0)] for i in range(N): if uf.same(i,X[0]-1): for e in edge[i]: if dist[i]==dist[e]: print('Yes') exit(0) Set=set() for i in range(K): Set.add(dist[X[i]-1]) if len(Set)==1: print('Yes') else: print('No')