結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | t98slider |
提出日時 | 2023-03-17 18:49:10 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,347 ms / 4,000 ms |
コード長 | 1,731 bytes |
コンパイル時間 | 232 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 137,096 KB |
最終ジャッジ日時 | 2024-11-22 14:15:02 |
合計ジャッジ時間 | 44,545 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
51,968 KB |
testcase_01 | AC | 51 ms
62,976 KB |
testcase_02 | AC | 42 ms
52,352 KB |
testcase_03 | AC | 1,347 ms
137,096 KB |
testcase_04 | AC | 296 ms
82,432 KB |
testcase_05 | AC | 286 ms
80,000 KB |
testcase_06 | AC | 279 ms
79,744 KB |
testcase_07 | AC | 146 ms
81,280 KB |
testcase_08 | AC | 289 ms
82,048 KB |
testcase_09 | AC | 285 ms
82,548 KB |
testcase_10 | AC | 344 ms
83,868 KB |
testcase_11 | AC | 304 ms
82,688 KB |
testcase_12 | AC | 296 ms
82,176 KB |
testcase_13 | AC | 325 ms
79,232 KB |
testcase_14 | AC | 388 ms
79,196 KB |
testcase_15 | AC | 594 ms
83,284 KB |
testcase_16 | AC | 312 ms
82,816 KB |
testcase_17 | AC | 329 ms
87,168 KB |
testcase_18 | AC | 287 ms
82,048 KB |
testcase_19 | AC | 205 ms
79,616 KB |
testcase_20 | AC | 677 ms
89,780 KB |
testcase_21 | AC | 856 ms
91,768 KB |
testcase_22 | AC | 725 ms
92,976 KB |
testcase_23 | AC | 641 ms
92,676 KB |
testcase_24 | AC | 684 ms
93,428 KB |
testcase_25 | AC | 639 ms
93,732 KB |
testcase_26 | AC | 656 ms
92,160 KB |
testcase_27 | AC | 636 ms
92,092 KB |
testcase_28 | AC | 715 ms
92,828 KB |
testcase_29 | AC | 692 ms
94,424 KB |
testcase_30 | AC | 688 ms
93,180 KB |
testcase_31 | AC | 679 ms
92,588 KB |
testcase_32 | AC | 1,258 ms
95,720 KB |
testcase_33 | AC | 1,263 ms
95,848 KB |
testcase_34 | AC | 1,218 ms
94,244 KB |
testcase_35 | AC | 1,209 ms
96,184 KB |
testcase_36 | AC | 1,214 ms
93,824 KB |
testcase_37 | AC | 1,287 ms
95,512 KB |
testcase_38 | AC | 1,214 ms
95,728 KB |
testcase_39 | AC | 1,226 ms
95,740 KB |
testcase_40 | AC | 1,196 ms
94,988 KB |
testcase_41 | AC | 640 ms
87,604 KB |
testcase_42 | AC | 1,084 ms
94,068 KB |
testcase_43 | AC | 1,223 ms
97,560 KB |
testcase_44 | AC | 1,128 ms
94,504 KB |
testcase_45 | AC | 1,061 ms
93,332 KB |
testcase_46 | AC | 923 ms
91,448 KB |
testcase_47 | AC | 843 ms
90,376 KB |
testcase_48 | AC | 781 ms
89,376 KB |
testcase_49 | AC | 723 ms
89,256 KB |
testcase_50 | AC | 657 ms
88,328 KB |
testcase_51 | AC | 642 ms
87,776 KB |
testcase_52 | AC | 648 ms
88,440 KB |
testcase_53 | AC | 571 ms
89,236 KB |
testcase_54 | AC | 622 ms
93,636 KB |
testcase_55 | AC | 577 ms
94,796 KB |
ソースコード
from sys import stdin class UnionFind(): def __init__(self, n): self.N = n self.siz = n self.parent_or_size = [-1] * n self.used_list = [] def leader(self, x): if self.parent_or_size[x] < 0: return x x = self.parent_or_size[x] if self.parent_or_size[x] < 0: return x self.parent_or_size[x] = self.leader(self.parent_or_size[x]) return self.parent_or_size[x] def same(self, x, y): return self.leader(x) == self.leader(y) def merge(self, x, y): rx, ry = self.leader(x), self.leader(y) if rx == ry: return if self.parent_or_size[rx] > self.parent_or_size[ry]: rx, ry = ry, rx self.parent_or_size[rx] += self.parent_or_size[ry] self.parent_or_size[ry] = rx self.siz -= 1 self.used_list.append(rx) self.used_list.append(ry) def reset(self): self.siz = self.N for pos in self.used_list: self.parent_or_size[pos] = -1 self.used_list.clear() N, Q = map(int, input().split()) is_zero = 0 uf = UnionFind(2 * N) pow2 = [0] * (N + 1) pow2[0] = 1 for i in range(N): pow2[i + 1] = (pow2[i] + pow2[i]) % 998244353 for _ in range(Q): query = list(map(int, stdin.readline().split())) if query[0] <= 2: query[1] -= 1 query[2] -= 1 if query[0] == 1: uf.merge(query[1], query[2]) uf.merge(query[1] + N, query[2] + N) else: uf.merge(query[1], query[2] + N) uf.merge(query[1] + N, query[2]) if uf.same(query[1], query[1] + N): is_zero = 1 else: is_zero = 0 uf.reset() print(0 if is_zero else pow2[uf.siz >> 1])