結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | t98slider |
提出日時 | 2023-03-25 15:15:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 811 ms / 4,000 ms |
コード長 | 1,699 bytes |
コンパイル時間 | 455 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 96,824 KB |
最終ジャッジ日時 | 2024-05-02 03:54:42 |
合計ジャッジ時間 | 32,053 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
53,760 KB |
testcase_01 | AC | 62 ms
64,768 KB |
testcase_02 | AC | 48 ms
53,760 KB |
testcase_03 | AC | 811 ms
96,824 KB |
testcase_04 | AC | 279 ms
82,176 KB |
testcase_05 | AC | 275 ms
80,000 KB |
testcase_06 | AC | 272 ms
79,872 KB |
testcase_07 | AC | 164 ms
81,536 KB |
testcase_08 | AC | 288 ms
82,944 KB |
testcase_09 | AC | 274 ms
82,304 KB |
testcase_10 | AC | 257 ms
82,304 KB |
testcase_11 | AC | 298 ms
82,176 KB |
testcase_12 | AC | 277 ms
82,176 KB |
testcase_13 | AC | 258 ms
77,824 KB |
testcase_14 | AC | 323 ms
78,464 KB |
testcase_15 | AC | 470 ms
80,640 KB |
testcase_16 | AC | 296 ms
82,944 KB |
testcase_17 | AC | 324 ms
83,712 KB |
testcase_18 | AC | 272 ms
82,048 KB |
testcase_19 | AC | 191 ms
79,616 KB |
testcase_20 | AC | 510 ms
85,376 KB |
testcase_21 | AC | 599 ms
85,856 KB |
testcase_22 | AC | 569 ms
87,096 KB |
testcase_23 | AC | 542 ms
87,456 KB |
testcase_24 | AC | 547 ms
88,016 KB |
testcase_25 | AC | 507 ms
86,580 KB |
testcase_26 | AC | 540 ms
87,152 KB |
testcase_27 | AC | 528 ms
86,460 KB |
testcase_28 | AC | 563 ms
86,596 KB |
testcase_29 | AC | 525 ms
87,312 KB |
testcase_30 | AC | 561 ms
87,416 KB |
testcase_31 | AC | 521 ms
86,916 KB |
testcase_32 | AC | 555 ms
86,180 KB |
testcase_33 | AC | 553 ms
86,392 KB |
testcase_34 | AC | 573 ms
85,900 KB |
testcase_35 | AC | 556 ms
86,816 KB |
testcase_36 | AC | 547 ms
85,740 KB |
testcase_37 | AC | 570 ms
85,820 KB |
testcase_38 | AC | 584 ms
85,664 KB |
testcase_39 | AC | 549 ms
86,084 KB |
testcase_40 | AC | 558 ms
85,376 KB |
testcase_41 | AC | 338 ms
83,772 KB |
testcase_42 | AC | 446 ms
85,084 KB |
testcase_43 | AC | 543 ms
85,428 KB |
testcase_44 | AC | 574 ms
86,232 KB |
testcase_45 | AC | 641 ms
86,008 KB |
testcase_46 | AC | 607 ms
86,980 KB |
testcase_47 | AC | 592 ms
85,676 KB |
testcase_48 | AC | 564 ms
85,224 KB |
testcase_49 | AC | 517 ms
84,744 KB |
testcase_50 | AC | 515 ms
85,508 KB |
testcase_51 | AC | 524 ms
84,816 KB |
testcase_52 | AC | 529 ms
85,844 KB |
testcase_53 | AC | 476 ms
85,196 KB |
testcase_54 | AC | 506 ms
87,632 KB |
testcase_55 | AC | 474 ms
86,508 KB |
ソースコード
from sys import stdin from collections import deque class UnionFind(): def __init__(self, n): self.N = n self.num_component = n self.parent_or_size = [-1] * n self.weight = [0] * n self.stack = deque() 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.stack.append(ry) self.stack.append(rx) def reset(self): self.num_component = self.N self.is_zero = False while len(self.stack): pos = self.stack.pop() self.parent_or_size[pos] = -1 self.weight[pos] = 0 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])