結果
問題 | No.2293 無向辺 2-SAT |
ユーザー | chineristAC |
提出日時 | 2023-05-05 21:53:37 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,920 bytes |
コンパイル時間 | 326 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 196,080 KB |
最終ジャッジ日時 | 2024-05-02 16:03:13 |
合計ジャッジ時間 | 22,736 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
56,448 KB |
testcase_01 | AC | 57 ms
69,248 KB |
testcase_02 | AC | 44 ms
55,936 KB |
testcase_03 | WA | - |
testcase_04 | AC | 409 ms
88,156 KB |
testcase_05 | AC | 438 ms
84,372 KB |
testcase_06 | AC | 369 ms
83,804 KB |
testcase_07 | AC | 218 ms
86,400 KB |
testcase_08 | AC | 392 ms
87,048 KB |
testcase_09 | AC | 350 ms
87,556 KB |
testcase_10 | WA | - |
testcase_11 | AC | 424 ms
88,980 KB |
testcase_12 | AC | 412 ms
86,868 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 414 ms
89,216 KB |
testcase_17 | AC | 522 ms
112,688 KB |
testcase_18 | AC | 390 ms
87,196 KB |
testcase_19 | AC | 251 ms
82,580 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 | TLE | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
ソースコード
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) N,Q = mi() parent = [(i,-1) for i in range(N)] sz = [1] * N contradict = False free = N parent_change = [] sz_change = [] contradict_change = [] free_change = [] def calc_val(v): res = 0 while parent[v][1]!=-1: res ^= parent[v][1] v = parent[v][0] return res def add_query(t,u,v,p): global contradict,free if parent[u][0] == parent[v][0]: cu,cv = calc_val(u),calc_val(v) if cu!=cv^p: contradict_change.append((t,contradict,True)) contradict = True return if sz[u] > sz[v]: u,v = v,u parent_change.append((t,u,parent[u],(v,p))) parent[u] = (v,p) sz_change.append((t,v,sz[v],sz[v]+sz[u])) sz[v] += sz[u] free_change.append((t,free,free-1)) free -= 1 def undo_query(t): global contradict,free while parent_change and parent_change[-1][0] == t: _,v,pre,now = parent_change.pop() parent[v] = pre while sz_change and sz_change[-1][0] == t: _,v,pre,now = sz_change.pop() sz[v] = pre while contradict_change and contradict_change[-1][0] == t: _,pre,now = contradict_change.pop() contradict = pre while free_change and free_change[-1][0] == t: _,pre,now = free_change.pop() free = pre time_stack = [] for tim in range(Q): t,*query = mi() if t == 1: u,v = query u,v = u-1,v-1 if u!=v: add_query(tim,u,v,1) time_stack.append(tim) elif t == 2: u,v = query u,v = u-1,v-1 if u!=v: add_query(tim,u,v,0) time_stack.append(tim) else: while time_stack: undo_query(time_stack.pop()) if contradict: print(0) else: print(pow(2,free,998244353))