結果
問題 |
No.1610 She Loves Me, She Loves Me Not, ...
|
ユーザー |
![]() |
提出日時 | 2023-12-20 14:55:17 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,757 bytes |
コンパイル時間 | 158 ms |
コンパイル使用メモリ | 82,512 KB |
実行使用メモリ | 77,696 KB |
最終ジャッジ日時 | 2024-09-27 09:51:38 |
合計ジャッジ時間 | 3,643 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 WA * 1 |
other | AC * 21 WA * 11 |
ソースコード
import pypyjit pypyjit.set_param('max_unroll_recursion=-1') import sys sys.setrecursionlimit(10**7) # UnionFind class UnionFind: def __init__(self,n): self.n=n self.parent_size=[-1]*n def leader(self,a): if self.parent_size[a]<0: return a self.parent_size[a]=self.leader(self.parent_size[a]) return self.parent_size[a] def merge(self,a,b): x,y=self.leader(a),self.leader(b) if x == y: return if abs(self.parent_size[x])<abs(self.parent_size[y]):x,y=y,x self.parent_size[x] += self.parent_size[y] self.parent_size[y]=x return def same(self,a,b): return self.leader(a) == self.leader(b) def size(self,a): return abs(self.parent_size[self.leader(a)]) def groups(self): result=[[] for _ in range(self.n)] for i in range(self.n): result[self.leader(i)].append(i) return [r for r in result if r != []] n,m = map(int,input().split()) edge = [[] for _ in range(n)] uf = UnionFind(n) into = [0]*n for _ in range(m): a,b = map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) uf.merge(a-1,b-1) into[a-1] += 1 into[b-1] += 1 ans = 0 def dfs(now): global ans for to in edge[now]: if into[to] == 0: continue if into[to] == 1: into[to] = 0 ans += 1 dfs(to) elif into[to] >= 2: into[to] -= 1 l = uf.groups() for lis in l: tmp = [] for now in lis: if into[now] == 1: tmp.append(now) for i in tmp: dfs(i) if (ans-1)%2 == 0: print("Yes") else: print("No")