結果
問題 | No.2948 move move rotti |
ユーザー | nikoro256 |
提出日時 | 2024-10-25 22:30:42 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,379 bytes |
コンパイル時間 | 359 ms |
コンパイル使用メモリ | 82,512 KB |
実行使用メモリ | 67,836 KB |
最終ジャッジ日時 | 2024-10-25 22:30:52 |
合計ジャッジ時間 | 2,871 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
55,796 KB |
testcase_01 | AC | 39 ms
54,664 KB |
testcase_02 | AC | 40 ms
55,652 KB |
testcase_03 | RE | - |
testcase_04 | AC | 40 ms
55,424 KB |
testcase_05 | AC | 41 ms
54,664 KB |
testcase_06 | RE | - |
testcase_07 | AC | 40 ms
54,828 KB |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | AC | 40 ms
54,908 KB |
testcase_12 | RE | - |
testcase_13 | AC | 44 ms
54,516 KB |
testcase_14 | AC | 42 ms
54,532 KB |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | AC | 41 ms
54,940 KB |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | AC | 38 ms
55,328 KB |
testcase_28 | RE | - |
testcase_29 | AC | 38 ms
54,688 KB |
testcase_30 | RE | - |
ソースコード
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]: assert False 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')