結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | t98slider |
提出日時 | 2023-03-25 08:13:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 802 ms / 4,000 ms |
コード長 | 1,676 bytes |
コンパイル時間 | 658 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 108,892 KB |
最終ジャッジ日時 | 2024-05-02 03:54:08 |
合計ジャッジ時間 | 31,489 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
52,096 KB |
testcase_01 | AC | 59 ms
63,488 KB |
testcase_02 | AC | 45 ms
52,352 KB |
testcase_03 | AC | 802 ms
108,892 KB |
testcase_04 | AC | 283 ms
82,176 KB |
testcase_05 | AC | 291 ms
80,128 KB |
testcase_06 | AC | 263 ms
79,232 KB |
testcase_07 | AC | 160 ms
81,152 KB |
testcase_08 | AC | 281 ms
81,664 KB |
testcase_09 | AC | 263 ms
81,792 KB |
testcase_10 | AC | 264 ms
82,304 KB |
testcase_11 | AC | 296 ms
81,792 KB |
testcase_12 | AC | 278 ms
81,664 KB |
testcase_13 | AC | 248 ms
77,696 KB |
testcase_14 | AC | 315 ms
78,080 KB |
testcase_15 | AC | 406 ms
78,804 KB |
testcase_16 | AC | 308 ms
82,432 KB |
testcase_17 | AC | 294 ms
83,200 KB |
testcase_18 | AC | 280 ms
81,536 KB |
testcase_19 | AC | 189 ms
78,976 KB |
testcase_20 | AC | 494 ms
85,044 KB |
testcase_21 | AC | 565 ms
85,840 KB |
testcase_22 | AC | 516 ms
86,968 KB |
testcase_23 | AC | 446 ms
86,052 KB |
testcase_24 | AC | 462 ms
84,920 KB |
testcase_25 | AC | 458 ms
85,424 KB |
testcase_26 | AC | 469 ms
86,360 KB |
testcase_27 | AC | 481 ms
85,492 KB |
testcase_28 | AC | 508 ms
86,084 KB |
testcase_29 | AC | 462 ms
85,284 KB |
testcase_30 | AC | 500 ms
86,380 KB |
testcase_31 | AC | 466 ms
85,440 KB |
testcase_32 | AC | 591 ms
85,700 KB |
testcase_33 | AC | 591 ms
85,156 KB |
testcase_34 | AC | 601 ms
85,460 KB |
testcase_35 | AC | 586 ms
85,420 KB |
testcase_36 | AC | 594 ms
86,188 KB |
testcase_37 | AC | 586 ms
86,148 KB |
testcase_38 | AC | 594 ms
85,752 KB |
testcase_39 | AC | 586 ms
85,960 KB |
testcase_40 | AC | 593 ms
86,376 KB |
testcase_41 | AC | 347 ms
83,312 KB |
testcase_42 | AC | 477 ms
84,440 KB |
testcase_43 | AC | 565 ms
85,184 KB |
testcase_44 | AC | 621 ms
86,288 KB |
testcase_45 | AC | 646 ms
86,056 KB |
testcase_46 | AC | 587 ms
85,864 KB |
testcase_47 | AC | 596 ms
85,864 KB |
testcase_48 | AC | 533 ms
84,788 KB |
testcase_49 | AC | 524 ms
84,300 KB |
testcase_50 | AC | 490 ms
84,348 KB |
testcase_51 | AC | 473 ms
83,968 KB |
testcase_52 | AC | 451 ms
84,492 KB |
testcase_53 | AC | 418 ms
84,292 KB |
testcase_54 | AC | 450 ms
85,540 KB |
testcase_55 | AC | 436 ms
86,348 KB |
ソースコード
from sys import stdin class UnionFind(): def __init__(self, n): self.N = n self.num_component = n self.parent_or_size = [-1] * n self.weight = [0] * n self.used_list = [] self.is_zero = False def leader(self, x): if self.parent_or_size[x] < 0: return x root = self.leader(self.parent_or_size[x]) self.weight[x] ^= self.weight[self.parent_or_size[x]] self.parent_or_size[x] = root return root def merge(self, x, y, w): rx, ry = self.leader(x), self.leader(y) w ^= self.weight[x] ^ self.weight[y] if rx == ry: if w: self.is_zero = True 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.weight[ry] = w self.num_component -= 1 self.used_list.append(ry) self.used_list.append(rx) def reset(self): self.num_component = self.N self.is_zero = False for pos in self.used_list: self.parent_or_size[pos] = -1 self.weight[pos] = 0 self.used_list.clear() N, Q = map(int, stdin.readline().split()) uf = UnionFind(N) pow2 = [0] * (N + 1) pow2[0] = 1 for i in range(N): pow2[i + 1] = pow2[i] + pow2[i] if pow2[i + 1] >= 998244353: pow2[i + 1] -= 998244353 for _ in range(Q): query = list(map(int, stdin.readline().split())) if query[0] <= 2: uf.merge(query[1] - 1, query[2] - 1, query[0] - 1) else: uf.reset() print(0 if uf.is_zero else pow2[uf.num_component])