結果
問題 | No.2536 同値性と充足可能性 |
ユーザー | aaaaaaaaaa2230 |
提出日時 | 2023-11-10 23:08:10 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 469 ms / 2,000 ms |
コード長 | 1,859 bytes |
コンパイル時間 | 156 ms |
コンパイル使用メモリ | 81,700 KB |
実行使用メモリ | 99,056 KB |
最終ジャッジ日時 | 2023-11-10 23:08:16 |
合計ジャッジ時間 | 5,876 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
53,588 KB |
testcase_01 | AC | 41 ms
53,588 KB |
testcase_02 | AC | 39 ms
53,588 KB |
testcase_03 | AC | 38 ms
53,588 KB |
testcase_04 | AC | 39 ms
53,588 KB |
testcase_05 | AC | 38 ms
53,588 KB |
testcase_06 | AC | 40 ms
53,588 KB |
testcase_07 | AC | 39 ms
53,588 KB |
testcase_08 | AC | 39 ms
53,588 KB |
testcase_09 | AC | 38 ms
53,588 KB |
testcase_10 | AC | 40 ms
53,588 KB |
testcase_11 | AC | 39 ms
53,588 KB |
testcase_12 | AC | 39 ms
53,588 KB |
testcase_13 | AC | 38 ms
53,588 KB |
testcase_14 | AC | 39 ms
53,588 KB |
testcase_15 | AC | 40 ms
53,588 KB |
testcase_16 | AC | 39 ms
53,588 KB |
testcase_17 | AC | 73 ms
72,976 KB |
testcase_18 | AC | 72 ms
70,900 KB |
testcase_19 | AC | 40 ms
53,588 KB |
testcase_20 | AC | 86 ms
76,180 KB |
testcase_21 | AC | 93 ms
76,172 KB |
testcase_22 | AC | 85 ms
76,180 KB |
testcase_23 | AC | 196 ms
81,400 KB |
testcase_24 | AC | 185 ms
81,688 KB |
testcase_25 | AC | 469 ms
97,416 KB |
testcase_26 | AC | 418 ms
98,520 KB |
testcase_27 | AC | 306 ms
93,080 KB |
testcase_28 | AC | 419 ms
99,056 KB |
testcase_29 | AC | 401 ms
97,328 KB |
testcase_30 | AC | 272 ms
92,964 KB |
ソースコード
class Unionfind: def __init__(self,n): self.uf = [-1]*n def find(self,x): if self.uf[x] < 0: return x else: self.uf[x] = self.find(self.uf[x]) return self.uf[x] def same(self,x,y): return self.find(x) == self.find(y) def union(self,x,y): x = self.find(x) y = self.find(y) if x == y: return False if self.uf[x] > self.uf[y]: x,y = y,x self.uf[x] += self.uf[y] self.uf[y] = x return True def size(self,x): x = self.find(x) return -self.uf[x] n,m = map(int,input().split()) uf = Unionfind(n) edges = [] for i in range(m): u,e,v = input().split() u,v = int(u)-1,int(v)-1 if e == "<==>": uf.union(u,v) else: edges.append([u,v]) e = [[] for i in range(n)] used = [-1]*n for u,v in edges: if uf.same(u,v): print("No") exit() u,v = uf.find(u),uf.find(v) e[u].append(v) e[v].append(u) ans = [0]*n for i in range(n): if uf.find(i) != i: continue if used[i] != -1: continue used[i] = 0 sizes = [0,0] indexs = [[] for i in range(2)] q = [i] while q: now = q.pop() indexs[used[now]].append(now) sizes[used[now]] += uf.size(now) for nex in e[now]: if used[nex] == -1: used[nex] = 1^used[now] q.append(nex) else: if used[nex] == used[now]: print("No") exit() if sizes[0] > sizes[1]: indexs[0],indexs[1] = indexs[1],indexs[0] for ind in indexs[1]: ans[ind] = 1 print("Yes") l = [] for i in range(n): if ans[uf.find(i)]: l.append(i+1) print(len(l)) print(*l)