結果
問題 | No.2536 同値性と充足可能性 |
ユーザー | yupooh |
提出日時 | 2023-11-10 22:32:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 613 ms / 2,000 ms |
コード長 | 2,536 bytes |
コンパイル時間 | 325 ms |
コンパイル使用メモリ | 82,852 KB |
実行使用メモリ | 134,528 KB |
最終ジャッジ日時 | 2024-09-26 01:54:47 |
合計ジャッジ時間 | 6,776 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
54,272 KB |
testcase_01 | AC | 39 ms
54,016 KB |
testcase_02 | AC | 38 ms
54,528 KB |
testcase_03 | AC | 37 ms
54,272 KB |
testcase_04 | AC | 39 ms
54,272 KB |
testcase_05 | AC | 39 ms
54,016 KB |
testcase_06 | AC | 38 ms
54,656 KB |
testcase_07 | AC | 39 ms
54,656 KB |
testcase_08 | AC | 40 ms
54,144 KB |
testcase_09 | AC | 40 ms
54,272 KB |
testcase_10 | AC | 39 ms
54,400 KB |
testcase_11 | AC | 38 ms
54,400 KB |
testcase_12 | AC | 38 ms
54,272 KB |
testcase_13 | AC | 38 ms
54,784 KB |
testcase_14 | AC | 38 ms
54,400 KB |
testcase_15 | AC | 38 ms
54,400 KB |
testcase_16 | AC | 37 ms
54,016 KB |
testcase_17 | AC | 57 ms
69,760 KB |
testcase_18 | AC | 56 ms
69,376 KB |
testcase_19 | AC | 40 ms
55,168 KB |
testcase_20 | AC | 66 ms
77,080 KB |
testcase_21 | AC | 78 ms
76,872 KB |
testcase_22 | AC | 83 ms
77,132 KB |
testcase_23 | AC | 248 ms
86,564 KB |
testcase_24 | AC | 254 ms
87,964 KB |
testcase_25 | AC | 613 ms
134,528 KB |
testcase_26 | AC | 611 ms
125,296 KB |
testcase_27 | AC | 459 ms
130,560 KB |
testcase_28 | AC | 550 ms
124,188 KB |
testcase_29 | AC | 522 ms
127,360 KB |
testcase_30 | AC | 381 ms
131,000 KB |
ソースコード
import sys input = sys.stdin.readline n,m=map(int,input().split()) adj=[set() for _ in range(n)] adj2=[set() for _ in range(n)] from collections import defaultdict,deque 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()) uf=UnionFind(n) for _ in range(m): l=list(map(str,input().split())) a=int(l[0])-1 b=int(l[2])-1 if l[1]=="<==>": adj[a].add(b) adj[b].add(a) else: adj2[a].add(b) adj2[b].add(a) uf.union(a,b) for i in range(n): for j in adj[i]: if j in adj2[i]: print("No") exit() dist = [-1]*n for i in range(n): if dist[i]!=-1: continue que = deque([i]) dist[i] = 0 while que: v = que.popleft() e = dist[v] for w in adj[v]: if dist[w] > -1: if dist[w]==1-e: print("No") exit() else: dist[w] = e que.append(w) for w in adj2[v]: if dist[w] > -1: if dist[w]==e: print("No") exit() else: dist[w] = 1-e que.append(w) ans=[] for l in list(uf.all_group_members().values()): zero=[] one=[] for i in l: if dist[i]==0: zero.append(i+1) else: one.append(i+1) if len(zero)>=len(one): ans+=zero else: ans+=one if len(ans)>=(n+1)//2: print("Yes") print(len(ans)) ans.sort() print(*ans) else: print("No")