結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | t98slider |
提出日時 | 2023-03-16 14:58:53 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,382 ms / 4,000 ms |
コード長 | 1,710 bytes |
コンパイル時間 | 543 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 40,428 KB |
最終ジャッジ日時 | 2024-05-02 03:49:35 |
合計ジャッジ時間 | 67,992 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
10,752 KB |
testcase_01 | AC | 147 ms
21,760 KB |
testcase_02 | AC | 31 ms
10,880 KB |
testcase_03 | AC | 1,382 ms
40,428 KB |
testcase_04 | AC | 1,124 ms
22,016 KB |
testcase_05 | AC | 1,047 ms
16,512 KB |
testcase_06 | AC | 1,028 ms
16,384 KB |
testcase_07 | AC | 606 ms
21,760 KB |
testcase_08 | AC | 1,103 ms
21,760 KB |
testcase_09 | AC | 963 ms
21,888 KB |
testcase_10 | AC | 967 ms
21,760 KB |
testcase_11 | AC | 1,139 ms
22,144 KB |
testcase_12 | AC | 1,094 ms
21,792 KB |
testcase_13 | AC | 928 ms
11,008 KB |
testcase_14 | AC | 932 ms
10,752 KB |
testcase_15 | AC | 878 ms
10,880 KB |
testcase_16 | AC | 1,123 ms
22,016 KB |
testcase_17 | AC | 1,197 ms
23,900 KB |
testcase_18 | AC | 1,128 ms
21,888 KB |
testcase_19 | AC | 567 ms
16,256 KB |
testcase_20 | AC | 1,171 ms
22,092 KB |
testcase_21 | AC | 1,160 ms
21,888 KB |
testcase_22 | AC | 1,256 ms
22,656 KB |
testcase_23 | AC | 1,281 ms
22,656 KB |
testcase_24 | AC | 1,291 ms
22,656 KB |
testcase_25 | AC | 1,241 ms
22,560 KB |
testcase_26 | AC | 1,267 ms
22,656 KB |
testcase_27 | AC | 1,267 ms
22,656 KB |
testcase_28 | AC | 1,277 ms
22,656 KB |
testcase_29 | AC | 1,273 ms
22,656 KB |
testcase_30 | AC | 1,291 ms
22,656 KB |
testcase_31 | AC | 1,291 ms
22,672 KB |
testcase_32 | AC | 1,138 ms
21,952 KB |
testcase_33 | AC | 1,112 ms
21,632 KB |
testcase_34 | AC | 1,089 ms
21,888 KB |
testcase_35 | AC | 1,119 ms
21,760 KB |
testcase_36 | AC | 1,117 ms
21,888 KB |
testcase_37 | AC | 1,126 ms
21,888 KB |
testcase_38 | AC | 1,122 ms
21,724 KB |
testcase_39 | AC | 1,094 ms
22,016 KB |
testcase_40 | AC | 1,098 ms
21,724 KB |
testcase_41 | AC | 976 ms
21,760 KB |
testcase_42 | AC | 1,060 ms
21,872 KB |
testcase_43 | AC | 1,080 ms
21,888 KB |
testcase_44 | AC | 1,129 ms
21,888 KB |
testcase_45 | AC | 1,150 ms
21,760 KB |
testcase_46 | AC | 1,176 ms
21,888 KB |
testcase_47 | AC | 1,173 ms
21,888 KB |
testcase_48 | AC | 1,183 ms
22,008 KB |
testcase_49 | AC | 1,176 ms
22,016 KB |
testcase_50 | AC | 1,172 ms
21,888 KB |
testcase_51 | AC | 1,187 ms
22,016 KB |
testcase_52 | AC | 1,213 ms
22,144 KB |
testcase_53 | AC | 1,221 ms
22,400 KB |
testcase_54 | AC | 1,236 ms
23,004 KB |
testcase_55 | AC | 1,245 ms
24,204 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, stdin.readline().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] if pow2[i + 1] >= 998244353: pow2[i + 1] -= 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() print(0 if is_zero else pow2[uf.siz >> 1])