結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | t98slider |
提出日時 | 2023-03-16 02:41:47 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,434 ms / 4,000 ms |
コード長 | 1,682 bytes |
コンパイル時間 | 512 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 137,476 KB |
最終ジャッジ日時 | 2024-05-02 03:47:05 |
合計ジャッジ時間 | 46,978 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
52,224 KB |
testcase_01 | AC | 53 ms
62,720 KB |
testcase_02 | AC | 42 ms
52,224 KB |
testcase_03 | AC | 1,434 ms
137,476 KB |
testcase_04 | AC | 318 ms
82,432 KB |
testcase_05 | AC | 314 ms
79,744 KB |
testcase_06 | AC | 303 ms
80,000 KB |
testcase_07 | AC | 153 ms
81,280 KB |
testcase_08 | AC | 309 ms
82,048 KB |
testcase_09 | AC | 303 ms
82,296 KB |
testcase_10 | AC | 368 ms
83,580 KB |
testcase_11 | AC | 330 ms
82,944 KB |
testcase_12 | AC | 312 ms
82,048 KB |
testcase_13 | AC | 356 ms
79,616 KB |
testcase_14 | AC | 428 ms
80,296 KB |
testcase_15 | AC | 645 ms
82,384 KB |
testcase_16 | AC | 334 ms
82,944 KB |
testcase_17 | AC | 365 ms
86,912 KB |
testcase_18 | AC | 304 ms
81,920 KB |
testcase_19 | AC | 219 ms
79,488 KB |
testcase_20 | AC | 728 ms
88,700 KB |
testcase_21 | AC | 901 ms
89,984 KB |
testcase_22 | AC | 742 ms
92,860 KB |
testcase_23 | AC | 700 ms
93,816 KB |
testcase_24 | AC | 731 ms
93,076 KB |
testcase_25 | AC | 661 ms
92,676 KB |
testcase_26 | AC | 705 ms
94,476 KB |
testcase_27 | AC | 718 ms
94,224 KB |
testcase_28 | AC | 727 ms
92,988 KB |
testcase_29 | AC | 726 ms
92,892 KB |
testcase_30 | AC | 731 ms
92,600 KB |
testcase_31 | AC | 685 ms
92,692 KB |
testcase_32 | AC | 1,241 ms
95,048 KB |
testcase_33 | AC | 1,237 ms
94,672 KB |
testcase_34 | AC | 1,246 ms
95,428 KB |
testcase_35 | AC | 1,174 ms
94,852 KB |
testcase_36 | AC | 1,203 ms
95,556 KB |
testcase_37 | AC | 1,205 ms
93,556 KB |
testcase_38 | AC | 1,248 ms
95,948 KB |
testcase_39 | AC | 1,269 ms
94,544 KB |
testcase_40 | AC | 1,254 ms
94,704 KB |
testcase_41 | AC | 658 ms
87,984 KB |
testcase_42 | AC | 1,069 ms
92,088 KB |
testcase_43 | AC | 1,250 ms
95,340 KB |
testcase_44 | AC | 1,199 ms
92,656 KB |
testcase_45 | AC | 1,063 ms
92,056 KB |
testcase_46 | AC | 966 ms
92,404 KB |
testcase_47 | AC | 906 ms
90,676 KB |
testcase_48 | AC | 850 ms
91,164 KB |
testcase_49 | AC | 764 ms
88,920 KB |
testcase_50 | AC | 743 ms
89,040 KB |
testcase_51 | AC | 662 ms
89,728 KB |
testcase_52 | AC | 653 ms
88,184 KB |
testcase_53 | AC | 642 ms
90,148 KB |
testcase_54 | AC | 648 ms
93,908 KB |
testcase_55 | AC | 598 ms
94,704 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 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() if is_zero == 1: print(0) else: print(pow2[uf.siz >> 1])