結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | chineristAC |
提出日時 | 2023-05-05 22:20:02 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,156 bytes |
コンパイル時間 | 273 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 139,260 KB |
最終ジャッジ日時 | 2024-11-23 08:46:40 |
合計ジャッジ時間 | 45,921 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
56,448 KB |
testcase_01 | AC | 69 ms
73,216 KB |
testcase_02 | AC | 54 ms
56,576 KB |
testcase_03 | AC | 633 ms
132,008 KB |
testcase_04 | AC | 774 ms
135,216 KB |
testcase_05 | AC | 729 ms
128,724 KB |
testcase_06 | AC | 715 ms
127,804 KB |
testcase_07 | AC | 264 ms
90,496 KB |
testcase_08 | AC | 749 ms
132,068 KB |
testcase_09 | AC | 670 ms
121,004 KB |
testcase_10 | WA | - |
testcase_11 | AC | 806 ms
137,268 KB |
testcase_12 | AC | 759 ms
134,520 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 790 ms
135,844 KB |
testcase_17 | AC | 821 ms
139,260 KB |
testcase_18 | AC | 755 ms
135,568 KB |
testcase_19 | AC | 433 ms
106,612 KB |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | WA | - |
testcase_49 | WA | - |
testcase_50 | WA | - |
testcase_51 | WA | - |
testcase_52 | WA | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
ソースコード
import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import gcd,log input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) class UnionFindVerSize(): def __init__(self, N): self._parent = [n for n in range(0, N)] self._size = [1] * N self.group = N def find_root(self, x): if self._parent[x] == x: return x self._parent[x] = self.find_root(self._parent[x]) return self._parent[x] def unite(self, x, y): gx = self.find_root(x) gy = self.find_root(y) if gx == gy: return self.group -= 1 if self._size[gx] < self._size[gy]: self._parent[gx] = gy self._size[gy] += self._size[gx] else: self._parent[gy] = gx self._size[gx] += self._size[gy] def get_size(self, x): return self._size[self.find_root(x)] def is_same_group(self, x, y): return self.find_root(x) == self.find_root(y) class WeightedUnionFind(): def __init__(self,N): self.n = N self.parent = [i for i in range(N)] self.size = [1 for i in range(N)] self.val = [0 for i in range(N)] self.flag = True self.edge = [[] for i in range(N)] self.change = [] self.free = N def dfs(self,v,pv): stack = [(v,pv)] new_parent = self.parent[pv] while stack: v,pv = stack.pop() self.parent[v] = new_parent for nv,w in self.edge[v]: if nv!=pv: self.val[nv] = self.val[v] + w stack.append((nv,v)) def unite(self,x,y,w): self.change.append(x) self.change.append(y) if not self.flag: return if self.parent[x]==self.parent[y]: self.flag &= (self.val[x] ^ self.val[y] == w) return self.free -= 1 if self.size[self.parent[x]]>self.size[self.parent[y]]: self.edge[x].append((y,w)) self.edge[y].append((x,w)) self.size[x] += self.size[y] self.val[y] = self.val[x] ^ w self.dfs(y,x) else: self.edge[x].append((y,w)) self.edge[y].append((x,w)) self.size[y] += self.size[x] self.val[x] = self.val[y] ^ w self.dfs(x,y) def reset(self): self.flag = True self.free = self.n for x in self.change: self.parent[x] = x self.size[x] = 1 self.val[x] = 0 self.edge[x] = [] self.change = [] N,Q = mi() uf = WeightedUnionFind(N) for _ in range(Q): t,*query = mi() if t == 1: u,v = query u,v = u-1,v-1 if u!=v: uf.unite(u,v,1) elif t == 2: u,v = query u,v = u-1,v-1 if u!=v: uf.unite(u,v,0) else: uf.reset() if uf.flag: print(pow(2,uf.free,998244353)) else: print(0)