結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | minimum |
提出日時 | 2023-05-05 22:27:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,684 ms / 4,000 ms |
コード長 | 2,330 bytes |
コンパイル時間 | 249 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 123,248 KB |
最終ジャッジ日時 | 2024-11-23 09:21:14 |
合計ジャッジ時間 | 87,828 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,096 KB |
testcase_01 | AC | 44 ms
55,936 KB |
testcase_02 | AC | 42 ms
52,352 KB |
testcase_03 | AC | 2,684 ms
123,248 KB |
testcase_04 | AC | 800 ms
80,256 KB |
testcase_05 | AC | 792 ms
78,592 KB |
testcase_06 | AC | 811 ms
78,756 KB |
testcase_07 | AC | 583 ms
79,744 KB |
testcase_08 | AC | 797 ms
80,280 KB |
testcase_09 | AC | 762 ms
80,512 KB |
testcase_10 | AC | 875 ms
82,732 KB |
testcase_11 | AC | 803 ms
80,740 KB |
testcase_12 | AC | 894 ms
81,120 KB |
testcase_13 | AC | 844 ms
79,528 KB |
testcase_14 | AC | 972 ms
80,924 KB |
testcase_15 | AC | 1,282 ms
82,208 KB |
testcase_16 | AC | 814 ms
80,368 KB |
testcase_17 | AC | 917 ms
86,220 KB |
testcase_18 | AC | 811 ms
80,660 KB |
testcase_19 | AC | 476 ms
78,592 KB |
testcase_20 | AC | 1,690 ms
89,772 KB |
testcase_21 | AC | 1,936 ms
90,772 KB |
testcase_22 | AC | 1,680 ms
96,088 KB |
testcase_23 | AC | 1,601 ms
93,804 KB |
testcase_24 | AC | 1,655 ms
95,832 KB |
testcase_25 | AC | 1,532 ms
92,944 KB |
testcase_26 | AC | 1,603 ms
92,956 KB |
testcase_27 | AC | 1,644 ms
94,220 KB |
testcase_28 | AC | 1,676 ms
94,052 KB |
testcase_29 | AC | 1,661 ms
94,676 KB |
testcase_30 | AC | 1,677 ms
96,268 KB |
testcase_31 | AC | 1,614 ms
96,172 KB |
testcase_32 | AC | 2,155 ms
94,828 KB |
testcase_33 | AC | 2,124 ms
94,336 KB |
testcase_34 | AC | 1,577 ms
87,976 KB |
testcase_35 | AC | 2,110 ms
94,828 KB |
testcase_36 | AC | 2,154 ms
94,916 KB |
testcase_37 | AC | 2,138 ms
95,724 KB |
testcase_38 | AC | 2,197 ms
94,324 KB |
testcase_39 | AC | 2,139 ms
94,584 KB |
testcase_40 | AC | 2,179 ms
96,668 KB |
testcase_41 | AC | 875 ms
83,116 KB |
testcase_42 | AC | 1,722 ms
91,300 KB |
testcase_43 | AC | 2,059 ms
92,364 KB |
testcase_44 | AC | 2,196 ms
95,824 KB |
testcase_45 | AC | 2,043 ms
94,296 KB |
testcase_46 | AC | 1,973 ms
92,964 KB |
testcase_47 | AC | 1,820 ms
90,808 KB |
testcase_48 | AC | 1,767 ms
90,352 KB |
testcase_49 | AC | 1,667 ms
89,416 KB |
testcase_50 | AC | 1,657 ms
90,312 KB |
testcase_51 | AC | 1,627 ms
89,852 KB |
testcase_52 | AC | 1,642 ms
90,372 KB |
testcase_53 | AC | 1,521 ms
93,804 KB |
testcase_54 | AC | 1,470 ms
93,092 KB |
testcase_55 | AC | 1,348 ms
95,076 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 = 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 dsu.merge(u, v + N) dsu.merge(v, u + N) if dsu.same(u, u + 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 dsu.merge(u, v) dsu.merge(u + N, v + N) if dsu.same(u, u + N): valid = 0 else: pass else: cnt = N for i in done: dsu.par_or_size[i] = -1 dsu.par_or_size[i + N] = -1 done = set() valid = 1 if valid: print(pow(2, cnt, MOD)) else: print(0)