結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | t98slider |
提出日時 | 2023-03-16 02:37:08 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 2,235 ms / 4,000 ms |
コード長 | 1,650 bytes |
コンパイル時間 | 192 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 40,320 KB |
最終ジャッジ日時 | 2024-05-02 03:40:01 |
合計ジャッジ時間 | 114,765 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 32 ms
10,752 KB |
testcase_01 | AC | 119 ms
21,632 KB |
testcase_02 | AC | 31 ms
10,752 KB |
testcase_03 | AC | 2,235 ms
40,320 KB |
testcase_04 | AC | 1,947 ms
21,888 KB |
testcase_05 | AC | 1,942 ms
16,256 KB |
testcase_06 | AC | 1,945 ms
16,256 KB |
testcase_07 | AC | 1,423 ms
21,760 KB |
testcase_08 | AC | 1,998 ms
21,760 KB |
testcase_09 | AC | 1,817 ms
21,888 KB |
testcase_10 | AC | 1,835 ms
21,888 KB |
testcase_11 | AC | 2,059 ms
21,888 KB |
testcase_12 | AC | 1,947 ms
21,760 KB |
testcase_13 | AC | 1,801 ms
11,136 KB |
testcase_14 | AC | 1,828 ms
10,880 KB |
testcase_15 | AC | 1,801 ms
10,752 KB |
testcase_16 | AC | 1,995 ms
21,888 KB |
testcase_17 | AC | 2,045 ms
23,680 KB |
testcase_18 | AC | 1,994 ms
21,632 KB |
testcase_19 | AC | 990 ms
16,384 KB |
testcase_20 | AC | 2,027 ms
21,760 KB |
testcase_21 | AC | 2,034 ms
21,888 KB |
testcase_22 | AC | 2,147 ms
22,400 KB |
testcase_23 | AC | 2,147 ms
22,528 KB |
testcase_24 | AC | 2,140 ms
22,400 KB |
testcase_25 | AC | 2,112 ms
22,528 KB |
testcase_26 | AC | 2,139 ms
22,656 KB |
testcase_27 | AC | 2,155 ms
22,528 KB |
testcase_28 | AC | 2,114 ms
22,528 KB |
testcase_29 | AC | 2,159 ms
22,528 KB |
testcase_30 | AC | 2,121 ms
22,528 KB |
testcase_31 | AC | 2,145 ms
22,400 KB |
testcase_32 | AC | 2,028 ms
21,760 KB |
testcase_33 | AC | 1,998 ms
21,760 KB |
testcase_34 | AC | 2,046 ms
21,760 KB |
testcase_35 | AC | 1,957 ms
21,760 KB |
testcase_36 | AC | 1,967 ms
21,760 KB |
testcase_37 | AC | 1,983 ms
21,760 KB |
testcase_38 | AC | 1,939 ms
21,760 KB |
testcase_39 | AC | 2,069 ms
21,760 KB |
testcase_40 | AC | 2,004 ms
21,760 KB |
testcase_41 | AC | 1,823 ms
21,760 KB |
testcase_42 | AC | 1,889 ms
21,632 KB |
testcase_43 | AC | 1,963 ms
21,888 KB |
testcase_44 | AC | 2,009 ms
21,888 KB |
testcase_45 | AC | 2,011 ms
21,632 KB |
testcase_46 | AC | 2,043 ms
21,760 KB |
testcase_47 | AC | 2,061 ms
21,760 KB |
testcase_48 | AC | 2,046 ms
21,760 KB |
testcase_49 | AC | 2,025 ms
21,760 KB |
testcase_50 | AC | 2,017 ms
21,760 KB |
testcase_51 | AC | 2,071 ms
21,888 KB |
testcase_52 | AC | 2,100 ms
22,016 KB |
testcase_53 | AC | 2,093 ms
22,400 KB |
testcase_54 | AC | 2,122 ms
23,040 KB |
testcase_55 | AC | 2,106 ms
24,160 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])