結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | t98slider |
提出日時 | 2023-03-16 02:43:32 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,290 ms / 4,000 ms |
コード長 | 1,691 bytes |
コンパイル時間 | 482 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 40,448 KB |
最終ジャッジ日時 | 2024-11-22 14:05:58 |
合計ジャッジ時間 | 64,765 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,880 KB |
testcase_01 | AC | 110 ms
21,632 KB |
testcase_02 | AC | 30 ms
10,752 KB |
testcase_03 | AC | 1,290 ms
40,448 KB |
testcase_04 | AC | 1,063 ms
21,888 KB |
testcase_05 | AC | 1,014 ms
16,384 KB |
testcase_06 | AC | 998 ms
16,512 KB |
testcase_07 | AC | 586 ms
21,632 KB |
testcase_08 | AC | 1,029 ms
21,760 KB |
testcase_09 | AC | 908 ms
21,760 KB |
testcase_10 | AC | 901 ms
21,632 KB |
testcase_11 | AC | 1,085 ms
22,016 KB |
testcase_12 | AC | 1,043 ms
22,016 KB |
testcase_13 | AC | 924 ms
11,264 KB |
testcase_14 | AC | 933 ms
10,880 KB |
testcase_15 | AC | 886 ms
10,752 KB |
testcase_16 | AC | 1,083 ms
22,016 KB |
testcase_17 | AC | 1,135 ms
23,936 KB |
testcase_18 | AC | 1,086 ms
21,760 KB |
testcase_19 | AC | 548 ms
16,256 KB |
testcase_20 | AC | 1,122 ms
21,888 KB |
testcase_21 | AC | 1,113 ms
21,760 KB |
testcase_22 | AC | 1,186 ms
22,400 KB |
testcase_23 | AC | 1,196 ms
22,784 KB |
testcase_24 | AC | 1,197 ms
22,528 KB |
testcase_25 | AC | 1,192 ms
22,528 KB |
testcase_26 | AC | 1,215 ms
22,784 KB |
testcase_27 | AC | 1,207 ms
22,528 KB |
testcase_28 | AC | 1,210 ms
22,528 KB |
testcase_29 | AC | 1,197 ms
22,528 KB |
testcase_30 | AC | 1,242 ms
22,528 KB |
testcase_31 | AC | 1,284 ms
22,784 KB |
testcase_32 | AC | 1,069 ms
21,760 KB |
testcase_33 | AC | 1,064 ms
21,888 KB |
testcase_34 | AC | 1,055 ms
21,632 KB |
testcase_35 | AC | 1,061 ms
21,632 KB |
testcase_36 | AC | 1,064 ms
21,760 KB |
testcase_37 | AC | 1,047 ms
21,632 KB |
testcase_38 | AC | 1,053 ms
21,888 KB |
testcase_39 | AC | 1,052 ms
21,632 KB |
testcase_40 | AC | 1,076 ms
21,632 KB |
testcase_41 | AC | 955 ms
21,888 KB |
testcase_42 | AC | 1,008 ms
21,888 KB |
testcase_43 | AC | 1,045 ms
21,888 KB |
testcase_44 | AC | 1,052 ms
21,760 KB |
testcase_45 | AC | 1,093 ms
21,760 KB |
testcase_46 | AC | 1,140 ms
21,760 KB |
testcase_47 | AC | 1,139 ms
21,888 KB |
testcase_48 | AC | 1,175 ms
21,760 KB |
testcase_49 | AC | 1,167 ms
21,760 KB |
testcase_50 | AC | 1,197 ms
22,016 KB |
testcase_51 | AC | 1,214 ms
21,888 KB |
testcase_52 | AC | 1,156 ms
22,016 KB |
testcase_53 | AC | 1,144 ms
22,528 KB |
testcase_54 | AC | 1,172 ms
22,912 KB |
testcase_55 | AC | 1,147 ms
24,208 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]) % 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])