結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | t98slider |
提出日時 | 2023-03-16 08:11:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,698 ms / 4,000 ms |
コード長 | 1,914 bytes |
コンパイル時間 | 452 ms |
コンパイル使用メモリ | 81,624 KB |
実行使用メモリ | 146,480 KB |
最終ジャッジ日時 | 2024-11-22 14:10:55 |
合計ジャッジ時間 | 55,826 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
53,504 KB |
testcase_01 | AC | 57 ms
64,384 KB |
testcase_02 | AC | 48 ms
53,376 KB |
testcase_03 | AC | 1,577 ms
146,480 KB |
testcase_04 | AC | 314 ms
83,072 KB |
testcase_05 | AC | 311 ms
81,152 KB |
testcase_06 | AC | 301 ms
80,640 KB |
testcase_07 | AC | 159 ms
81,536 KB |
testcase_08 | AC | 312 ms
83,172 KB |
testcase_09 | AC | 310 ms
82,476 KB |
testcase_10 | AC | 357 ms
83,660 KB |
testcase_11 | AC | 318 ms
83,200 KB |
testcase_12 | AC | 306 ms
83,584 KB |
testcase_13 | AC | 370 ms
80,512 KB |
testcase_14 | AC | 490 ms
82,604 KB |
testcase_15 | AC | 764 ms
88,304 KB |
testcase_16 | AC | 348 ms
83,672 KB |
testcase_17 | AC | 397 ms
89,476 KB |
testcase_18 | AC | 316 ms
83,072 KB |
testcase_19 | AC | 226 ms
80,256 KB |
testcase_20 | AC | 849 ms
91,796 KB |
testcase_21 | AC | 1,110 ms
95,948 KB |
testcase_22 | AC | 962 ms
102,816 KB |
testcase_23 | AC | 823 ms
98,132 KB |
testcase_24 | AC | 914 ms
101,448 KB |
testcase_25 | AC | 801 ms
99,908 KB |
testcase_26 | AC | 855 ms
99,776 KB |
testcase_27 | AC | 882 ms
100,176 KB |
testcase_28 | AC | 926 ms
100,024 KB |
testcase_29 | AC | 879 ms
99,584 KB |
testcase_30 | AC | 901 ms
99,124 KB |
testcase_31 | AC | 876 ms
101,288 KB |
testcase_32 | AC | 1,649 ms
104,424 KB |
testcase_33 | AC | 1,587 ms
104,648 KB |
testcase_34 | AC | 1,590 ms
104,708 KB |
testcase_35 | AC | 1,623 ms
108,132 KB |
testcase_36 | AC | 1,664 ms
108,348 KB |
testcase_37 | AC | 1,698 ms
105,428 KB |
testcase_38 | AC | 1,639 ms
107,052 KB |
testcase_39 | AC | 1,630 ms
104,892 KB |
testcase_40 | AC | 1,598 ms
105,144 KB |
testcase_41 | AC | 923 ms
95,104 KB |
testcase_42 | AC | 1,478 ms
102,636 KB |
testcase_43 | AC | 1,667 ms
107,684 KB |
testcase_44 | AC | 1,506 ms
102,464 KB |
testcase_45 | AC | 1,417 ms
102,980 KB |
testcase_46 | AC | 1,208 ms
101,028 KB |
testcase_47 | AC | 1,092 ms
96,836 KB |
testcase_48 | AC | 978 ms
93,748 KB |
testcase_49 | AC | 927 ms
92,912 KB |
testcase_50 | AC | 860 ms
92,756 KB |
testcase_51 | AC | 837 ms
94,552 KB |
testcase_52 | AC | 826 ms
95,204 KB |
testcase_53 | AC | 749 ms
96,052 KB |
testcase_54 | AC | 826 ms
100,084 KB |
testcase_55 | AC | 795 ms
102,124 KB |
ソースコード
from sys import stdin from collections import deque class UnionFind(): def __init__(self, n): self.N = n self.siz = n self.parent_or_size = [-1] * n self.stack = deque() self.used_list = [] def leader(self, x): if self.parent_or_size[x] < 0: return x self.stack.append(x) x = self.parent_or_size[x] while self.parent_or_size[x] >= 0: self.stack.append(x) x = self.parent_or_size[x] while len(self.stack): self.parent_or_size[self.stack.pop()] = x return 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() if is_zero == 1: print(0) else: print(pow2[uf.siz >> 1])