結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | t98slider |
提出日時 | 2023-03-25 08:14:03 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,038 ms / 4,000 ms |
コード長 | 1,676 bytes |
コンパイル時間 | 419 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 31,360 KB |
最終ジャッジ日時 | 2024-11-22 14:15:56 |
合計ジャッジ時間 | 52,886 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
10,752 KB |
testcase_01 | AC | 142 ms
21,760 KB |
testcase_02 | AC | 31 ms
10,880 KB |
testcase_03 | AC | 1,038 ms
31,360 KB |
testcase_04 | AC | 877 ms
22,016 KB |
testcase_05 | AC | 807 ms
16,256 KB |
testcase_06 | AC | 788 ms
16,384 KB |
testcase_07 | AC | 578 ms
21,632 KB |
testcase_08 | AC | 865 ms
21,888 KB |
testcase_09 | AC | 789 ms
21,632 KB |
testcase_10 | AC | 777 ms
21,760 KB |
testcase_11 | AC | 867 ms
21,888 KB |
testcase_12 | AC | 844 ms
21,888 KB |
testcase_13 | AC | 694 ms
11,136 KB |
testcase_14 | AC | 695 ms
10,752 KB |
testcase_15 | AC | 688 ms
10,752 KB |
testcase_16 | AC | 865 ms
21,760 KB |
testcase_17 | AC | 899 ms
22,912 KB |
testcase_18 | AC | 866 ms
21,760 KB |
testcase_19 | AC | 434 ms
16,384 KB |
testcase_20 | AC | 905 ms
21,760 KB |
testcase_21 | AC | 887 ms
21,760 KB |
testcase_22 | AC | 930 ms
22,272 KB |
testcase_23 | AC | 925 ms
22,016 KB |
testcase_24 | AC | 915 ms
22,400 KB |
testcase_25 | AC | 940 ms
22,400 KB |
testcase_26 | AC | 913 ms
22,400 KB |
testcase_27 | AC | 925 ms
22,272 KB |
testcase_28 | AC | 984 ms
22,272 KB |
testcase_29 | AC | 985 ms
22,016 KB |
testcase_30 | AC | 925 ms
22,016 KB |
testcase_31 | AC | 926 ms
22,272 KB |
testcase_32 | AC | 863 ms
21,760 KB |
testcase_33 | AC | 840 ms
21,632 KB |
testcase_34 | AC | 850 ms
21,632 KB |
testcase_35 | AC | 853 ms
21,760 KB |
testcase_36 | AC | 849 ms
21,760 KB |
testcase_37 | AC | 840 ms
21,888 KB |
testcase_38 | AC | 853 ms
21,888 KB |
testcase_39 | AC | 847 ms
21,632 KB |
testcase_40 | AC | 838 ms
21,760 KB |
testcase_41 | AC | 768 ms
21,760 KB |
testcase_42 | AC | 817 ms
21,760 KB |
testcase_43 | AC | 837 ms
21,760 KB |
testcase_44 | AC | 860 ms
21,760 KB |
testcase_45 | AC | 871 ms
21,760 KB |
testcase_46 | AC | 882 ms
21,760 KB |
testcase_47 | AC | 907 ms
21,888 KB |
testcase_48 | AC | 888 ms
21,888 KB |
testcase_49 | AC | 894 ms
21,888 KB |
testcase_50 | AC | 903 ms
21,888 KB |
testcase_51 | AC | 908 ms
21,888 KB |
testcase_52 | AC | 912 ms
22,016 KB |
testcase_53 | AC | 920 ms
22,016 KB |
testcase_54 | AC | 920 ms
22,400 KB |
testcase_55 | AC | 941 ms
23,040 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])