結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | rlangevin |
提出日時 | 2023-05-05 23:18:27 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,522 bytes |
コンパイル時間 | 1,719 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 117,284 KB |
最終ジャッジ日時 | 2024-05-02 18:27:45 |
合計ジャッジ時間 | 45,398 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
52,096 KB |
testcase_01 | AC | 63 ms
64,512 KB |
testcase_02 | AC | 45 ms
52,352 KB |
testcase_03 | WA | - |
testcase_04 | AC | 359 ms
84,096 KB |
testcase_05 | AC | 343 ms
80,640 KB |
testcase_06 | AC | 325 ms
80,896 KB |
testcase_07 | AC | 147 ms
82,560 KB |
testcase_08 | AC | 340 ms
84,224 KB |
testcase_09 | AC | 314 ms
83,884 KB |
testcase_10 | WA | - |
testcase_11 | AC | 370 ms
84,224 KB |
testcase_12 | AC | 342 ms
83,840 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 360 ms
84,096 KB |
testcase_17 | AC | 437 ms
88,968 KB |
testcase_18 | AC | 350 ms
83,584 KB |
testcase_19 | AC | 234 ms
80,128 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
ソースコード
import sys input = sys.stdin.readline class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] self.diff_weight = [0 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) self.diff_weight[x] ^= self.diff_weight[self.par[x]] return self.par[x] def union(self, x, y, w): rx = self.find(x) ry = self.find(y) c = self.diff_weight[y]^self.diff_weight[x] if rx != ry: if self.rank[rx] < self.rank[ry]: rx, ry = ry, rx if self.rank[rx] == self.rank[ry]: self.rank[rx] += 1 self.par[ry] = rx self.size[rx] += self.size[ry] self.diff_weight[ry] = w^c def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] def diff(self, x, y): return self.diff_weight[self.find(y)]^self.diff_weight[self.find(x)] N, Q = map(int, input().split()) flag = 1 mod = 998244353 N2 = pow(2, N, mod) ans = N2 inv = pow(2, mod - 2, mod) U = UnionFind(N) stack = set() for _ in range(Q): query = list(map(int, input().split())) if query[0] == 1: u, v = query[1:] u, v = u - 1, v - 1 if u == v: if flag: print(ans) else: print(0) continue stack.add(u) stack.add(v) if U.is_same(u, v): if U.diff(u, v) == 1: flag = 0 else: U.union(u, v, 0) ans *= inv ans %= mod elif query[0] == 2: u, v = query[1:] u, v = u - 1, v - 1 if u == v: if flag: print(ans) else: print(0) continue stack.add(u) stack.add(v) if U.is_same(u, v): if U.diff(u, v) == 0: flag = 0 else: U.union(u, v, 1) ans *= inv ans %= mod else: ans = N2 flag = 1 for s in stack: U.diff_weight[s] = 0 U.par[s] = s U.rank[s] = 0 U.size[s] = 1 stack = set() if flag: print(ans) else: print(0)