結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | t98slider |
提出日時 | 2023-03-16 02:34:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,774 ms / 4,000 ms |
コード長 | 1,654 bytes |
コンパイル時間 | 369 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 131,104 KB |
最終ジャッジ日時 | 2024-05-02 03:41:30 |
合計ジャッジ時間 | 67,549 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
51,712 KB |
testcase_01 | AC | 51 ms
62,848 KB |
testcase_02 | AC | 42 ms
52,352 KB |
testcase_03 | AC | 1,774 ms
131,104 KB |
testcase_04 | AC | 701 ms
82,176 KB |
testcase_05 | AC | 693 ms
79,744 KB |
testcase_06 | AC | 693 ms
79,744 KB |
testcase_07 | AC | 530 ms
80,768 KB |
testcase_08 | AC | 704 ms
82,284 KB |
testcase_09 | AC | 676 ms
82,176 KB |
testcase_10 | AC | 750 ms
83,820 KB |
testcase_11 | AC | 714 ms
81,816 KB |
testcase_12 | AC | 703 ms
81,664 KB |
testcase_13 | AC | 753 ms
79,496 KB |
testcase_14 | AC | 819 ms
79,408 KB |
testcase_15 | AC | 1,002 ms
81,544 KB |
testcase_16 | AC | 709 ms
82,052 KB |
testcase_17 | AC | 733 ms
86,608 KB |
testcase_18 | AC | 686 ms
81,692 KB |
testcase_19 | AC | 410 ms
79,104 KB |
testcase_20 | AC | 1,097 ms
85,664 KB |
testcase_21 | AC | 1,315 ms
89,928 KB |
testcase_22 | AC | 1,121 ms
91,184 KB |
testcase_23 | AC | 1,092 ms
92,472 KB |
testcase_24 | AC | 1,112 ms
91,464 KB |
testcase_25 | AC | 1,026 ms
90,628 KB |
testcase_26 | AC | 1,051 ms
91,044 KB |
testcase_27 | AC | 1,074 ms
91,064 KB |
testcase_28 | AC | 1,131 ms
94,268 KB |
testcase_29 | AC | 1,097 ms
92,480 KB |
testcase_30 | AC | 1,103 ms
92,224 KB |
testcase_31 | AC | 1,094 ms
91,612 KB |
testcase_32 | AC | 1,622 ms
93,000 KB |
testcase_33 | AC | 1,599 ms
92,752 KB |
testcase_34 | AC | 1,612 ms
90,968 KB |
testcase_35 | AC | 1,630 ms
92,452 KB |
testcase_36 | AC | 1,617 ms
91,976 KB |
testcase_37 | AC | 1,556 ms
91,332 KB |
testcase_38 | AC | 1,601 ms
92,952 KB |
testcase_39 | AC | 1,622 ms
91,572 KB |
testcase_40 | AC | 1,638 ms
92,056 KB |
testcase_41 | AC | 1,014 ms
85,836 KB |
testcase_42 | AC | 1,485 ms
90,016 KB |
testcase_43 | AC | 1,601 ms
92,652 KB |
testcase_44 | AC | 1,534 ms
90,240 KB |
testcase_45 | AC | 1,493 ms
90,380 KB |
testcase_46 | AC | 1,328 ms
88,372 KB |
testcase_47 | AC | 1,255 ms
87,304 KB |
testcase_48 | AC | 1,182 ms
87,592 KB |
testcase_49 | AC | 1,155 ms
87,304 KB |
testcase_50 | AC | 1,081 ms
86,232 KB |
testcase_51 | AC | 1,043 ms
86,144 KB |
testcase_52 | AC | 1,024 ms
87,072 KB |
testcase_53 | AC | 1,017 ms
89,740 KB |
testcase_54 | AC | 1,067 ms
94,252 KB |
testcase_55 | AC | 1,009 ms
94,440 KB |
ソースコード
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, input().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])