結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | minimum |
提出日時 | 2023-05-05 22:25:09 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,503 bytes |
コンパイル時間 | 190 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 220,684 KB |
最終ジャッジ日時 | 2024-11-23 09:08:39 |
合計ジャッジ時間 | 181,090 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
57,856 KB |
testcase_01 | AC | 46 ms
61,568 KB |
testcase_02 | AC | 43 ms
57,856 KB |
testcase_03 | AC | 2,667 ms
218,200 KB |
testcase_04 | AC | 3,351 ms
107,336 KB |
testcase_05 | AC | 2,315 ms
176,488 KB |
testcase_06 | TLE | - |
testcase_07 | AC | 582 ms
165,788 KB |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | AC | 2,246 ms
200,592 KB |
testcase_12 | TLE | - |
testcase_13 | AC | 1,308 ms
190,852 KB |
testcase_14 | AC | 1,017 ms
85,852 KB |
testcase_15 | AC | 1,242 ms
179,352 KB |
testcase_16 | AC | 2,743 ms
107,012 KB |
testcase_17 | AC | 1,387 ms
203,588 KB |
testcase_18 | TLE | - |
testcase_19 | AC | 1,818 ms
188,596 KB |
testcase_20 | AC | 2,462 ms
115,324 KB |
testcase_21 | TLE | - |
testcase_22 | AC | 1,550 ms
112,364 KB |
testcase_23 | AC | 1,798 ms
211,444 KB |
testcase_24 | AC | 1,936 ms
117,020 KB |
testcase_25 | AC | 1,869 ms
205,584 KB |
testcase_26 | AC | 1,845 ms
117,476 KB |
testcase_27 | AC | 1,799 ms
210,764 KB |
testcase_28 | AC | 1,770 ms
115,532 KB |
testcase_29 | AC | 1,770 ms
210,552 KB |
testcase_30 | AC | 1,489 ms
111,208 KB |
testcase_31 | AC | 1,771 ms
211,172 KB |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | TLE | - |
testcase_35 | TLE | - |
testcase_36 | TLE | - |
testcase_37 | TLE | - |
testcase_38 | TLE | - |
testcase_39 | TLE | - |
testcase_40 | TLE | - |
testcase_41 | TLE | - |
testcase_42 | TLE | - |
testcase_43 | TLE | - |
testcase_44 | TLE | - |
testcase_45 | TLE | - |
testcase_46 | TLE | - |
testcase_47 | TLE | - |
testcase_48 | AC | 3,593 ms
111,780 KB |
testcase_49 | AC | 2,747 ms
110,988 KB |
testcase_50 | AC | 2,492 ms
112,744 KB |
testcase_51 | AC | 2,209 ms
114,576 KB |
testcase_52 | AC | 1,633 ms
107,968 KB |
testcase_53 | AC | 2,056 ms
110,032 KB |
testcase_54 | AC | 1,981 ms
111,424 KB |
testcase_55 | AC | 1,497 ms
220,684 KB |
ソースコード
class DisjointSetUnion(): def __init__(self, n): self.n = n self.par_or_size = [-1] * n def merge(self, a, b): assert(0 <= a < self.n) assert(0 <= b < self.n) la = self.leader(a) lb = self.leader(b) if la == lb: return la if -self.par_or_size[la] < -self.par_or_size[lb]: la, lb = lb, la self.par_or_size[la] += self.par_or_size[lb] self.par_or_size[lb] = la return la def same(self, a, b): assert(0 <= a < self.n) assert(0 <= b < self.n) return self.leader(a) == self.leader(b) def leader(self, a): assert(0 <= a < self.n) if (self.par_or_size[a] < 0): return a else: self.par_or_size[a] = self.leader(self.par_or_size[a]) return self.par_or_size[a] def size(self, a): assert(0 <= a < self.n) return - self.par_or_size[self.leader(a)] def group(self): result = dict() for a in range(self.n): la = self.leader(a) if la not in result: result[la] = [] result[la].append(a) return result MOD = 998244353 N, Q = map(int, input().split()) cnt = 2 * N valid = 1 dsu = DisjointSetUnion(2 * N) done = set() for _ in range(Q): query = list(map(int, input().split())) if query[0] == 2: u, v = query[1] - 1, query[2] - 1 if u != v: done.add(u) done.add(v) if not dsu.same(u, v + N): cnt -= 1 if not dsu.same(v, u + N): cnt -= 1 dsu.merge(u, v + N) dsu.merge(v, u + N) if dsu.same(u, u + N) or dsu.same(v, v + N): valid = 0 else: valid = 0 elif query[0] == 1: u, v = query[1] - 1, query[2] - 1 if u != v: done.add(u) done.add(v) if not dsu.same(u, v): cnt -= 1 if not dsu.same(u + N, v + N): cnt -= 1 dsu.merge(u, v) dsu.merge(u + N, v + N) if dsu.same(u, u + N) or dsu.same(v, v + N): valid = 0 else: pass else: cnt = 2 * N for i in done: dsu.par_or_size[i] = -1 dsu.par_or_size[i + N] = -1 valid = 1 if valid: print(pow(2, cnt // 2, MOD)) else: print(0)