結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | t98slider |
提出日時 | 2023-03-16 07:49:15 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,375 ms / 4,000 ms |
コード長 | 1,740 bytes |
コンパイル時間 | 425 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 40,448 KB |
最終ジャッジ日時 | 2024-05-02 03:42:42 |
合計ジャッジ時間 | 67,529 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
10,880 KB |
testcase_01 | AC | 144 ms
21,632 KB |
testcase_02 | AC | 31 ms
10,880 KB |
testcase_03 | AC | 1,375 ms
40,448 KB |
testcase_04 | AC | 1,141 ms
22,144 KB |
testcase_05 | AC | 1,037 ms
16,512 KB |
testcase_06 | AC | 1,043 ms
16,512 KB |
testcase_07 | AC | 613 ms
21,760 KB |
testcase_08 | AC | 1,094 ms
21,760 KB |
testcase_09 | AC | 960 ms
21,760 KB |
testcase_10 | AC | 957 ms
21,632 KB |
testcase_11 | AC | 1,141 ms
21,888 KB |
testcase_12 | AC | 1,091 ms
21,888 KB |
testcase_13 | AC | 915 ms
11,264 KB |
testcase_14 | AC | 938 ms
10,752 KB |
testcase_15 | AC | 889 ms
10,880 KB |
testcase_16 | AC | 1,163 ms
22,144 KB |
testcase_17 | AC | 1,233 ms
23,936 KB |
testcase_18 | AC | 1,121 ms
21,888 KB |
testcase_19 | AC | 578 ms
16,512 KB |
testcase_20 | AC | 1,180 ms
21,888 KB |
testcase_21 | AC | 1,166 ms
21,760 KB |
testcase_22 | AC | 1,275 ms
22,656 KB |
testcase_23 | AC | 1,272 ms
22,528 KB |
testcase_24 | AC | 1,254 ms
22,656 KB |
testcase_25 | AC | 1,253 ms
22,400 KB |
testcase_26 | AC | 1,248 ms
22,656 KB |
testcase_27 | AC | 1,268 ms
22,528 KB |
testcase_28 | AC | 1,277 ms
22,656 KB |
testcase_29 | AC | 1,276 ms
22,656 KB |
testcase_30 | AC | 1,260 ms
22,528 KB |
testcase_31 | AC | 1,235 ms
22,528 KB |
testcase_32 | AC | 1,093 ms
21,888 KB |
testcase_33 | AC | 1,241 ms
21,760 KB |
testcase_34 | AC | 1,101 ms
21,760 KB |
testcase_35 | AC | 1,114 ms
21,888 KB |
testcase_36 | AC | 1,131 ms
21,632 KB |
testcase_37 | AC | 1,110 ms
21,888 KB |
testcase_38 | AC | 1,104 ms
21,888 KB |
testcase_39 | AC | 1,096 ms
21,760 KB |
testcase_40 | AC | 1,115 ms
21,760 KB |
testcase_41 | AC | 988 ms
22,016 KB |
testcase_42 | AC | 1,059 ms
21,760 KB |
testcase_43 | AC | 1,086 ms
21,632 KB |
testcase_44 | AC | 1,127 ms
21,888 KB |
testcase_45 | AC | 1,155 ms
21,760 KB |
testcase_46 | AC | 1,175 ms
22,016 KB |
testcase_47 | AC | 1,263 ms
21,888 KB |
testcase_48 | AC | 1,215 ms
21,888 KB |
testcase_49 | AC | 1,201 ms
21,760 KB |
testcase_50 | AC | 1,172 ms
21,888 KB |
testcase_51 | AC | 1,206 ms
22,016 KB |
testcase_52 | AC | 1,236 ms
22,144 KB |
testcase_53 | AC | 1,256 ms
22,528 KB |
testcase_54 | AC | 1,307 ms
23,168 KB |
testcase_55 | AC | 1,285 ms
24,200 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() if is_zero == 1: print(0) else: print(pow2[uf.siz >> 1])