結果

問題 No.2293 無向辺 2-SAT
ユーザー ニックネームニックネーム
提出日時 2023-05-05 22:38:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,897 ms / 4,000 ms
コード長 917 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 86,512 KB
実行使用メモリ 162,804 KB
最終ジャッジ日時 2023-08-15 05:27:19
合計ジャッジ時間 94,352 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
70,960 KB
testcase_01 AC 79 ms
71,128 KB
testcase_02 AC 74 ms
71,336 KB
testcase_03 AC 2,897 ms
162,804 KB
testcase_04 AC 1,005 ms
80,224 KB
testcase_05 AC 928 ms
81,908 KB
testcase_06 AC 900 ms
79,440 KB
testcase_07 AC 604 ms
78,008 KB
testcase_08 AC 870 ms
79,300 KB
testcase_09 AC 810 ms
79,352 KB
testcase_10 AC 823 ms
79,128 KB
testcase_11 AC 915 ms
81,060 KB
testcase_12 AC 891 ms
79,304 KB
testcase_13 AC 916 ms
79,888 KB
testcase_14 AC 1,162 ms
84,928 KB
testcase_15 AC 1,469 ms
91,120 KB
testcase_16 AC 913 ms
80,840 KB
testcase_17 AC 1,062 ms
101,688 KB
testcase_18 AC 890 ms
80,088 KB
testcase_19 AC 536 ms
79,308 KB
testcase_20 AC 1,829 ms
94,404 KB
testcase_21 AC 1,997 ms
98,356 KB
testcase_22 AC 1,876 ms
119,508 KB
testcase_23 AC 1,816 ms
114,312 KB
testcase_24 AC 1,951 ms
113,356 KB
testcase_25 AC 1,787 ms
112,132 KB
testcase_26 AC 1,844 ms
113,704 KB
testcase_27 AC 1,942 ms
113,712 KB
testcase_28 AC 1,812 ms
113,716 KB
testcase_29 AC 2,035 ms
115,316 KB
testcase_30 AC 1,966 ms
114,944 KB
testcase_31 AC 1,848 ms
115,812 KB
testcase_32 AC 1,917 ms
93,800 KB
testcase_33 AC 2,055 ms
94,824 KB
testcase_34 AC 1,909 ms
94,848 KB
testcase_35 AC 1,943 ms
94,820 KB
testcase_36 AC 1,952 ms
97,920 KB
testcase_37 AC 2,032 ms
94,188 KB
testcase_38 AC 1,903 ms
95,284 KB
testcase_39 AC 1,897 ms
98,260 KB
testcase_40 AC 1,901 ms
95,220 KB
testcase_41 AC 1,022 ms
82,920 KB
testcase_42 AC 1,562 ms
90,056 KB
testcase_43 AC 1,797 ms
89,276 KB
testcase_44 AC 1,971 ms
97,664 KB
testcase_45 AC 2,051 ms
95,436 KB
testcase_46 AC 1,756 ms
91,068 KB
testcase_47 AC 1,908 ms
98,864 KB
testcase_48 AC 1,884 ms
95,652 KB
testcase_49 AC 1,891 ms
96,020 KB
testcase_50 AC 1,864 ms
96,668 KB
testcase_51 AC 1,736 ms
99,900 KB
testcase_52 AC 1,664 ms
103,236 KB
testcase_53 AC 1,641 ms
105,308 KB
testcase_54 AC 1,688 ms
115,812 KB
testcase_55 AC 1,641 ms
119,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class UF:
    def __init__(self,n):
        self.p = {}
    def f(self,x):
        if x not in self.p: self.p[x] = -1; return x
        elif self.p[x]<0: return x
        else: self.p[x] = self.f(self.p[x]); return self.p[x]
    def u(self,x,y):
        x = self.f(x); y = self.f(y)
        if x==y: return
        if -self.p[x]<-self.p[y]: x,y = y,x
        self.p[x] += self.p[y]; self.p[y] = x
    def s(self,x,y): return self.f(x) == self.f(y)
n,q = map(int,input().split())
mod = 998244353; uf = UF(2*n); c = n
for _ in range(q):
    t,*uv = map(int,input().split())
    if t==1:
        u,v = [w-1 for w in uv]
        if uf.s(u,v+n): c = -1
        elif not uf.s(u,v): uf.u(u,v); uf.u(u+n,v+n); c -= 1
    if t==2:
        u,v = [w-1 for w in uv]
        if uf.s(u,v): c = -1
        elif not uf.s(u,v+n): uf.u(u,v+n); uf.u(u+n,v); c -= 1
    if t==3: uf = UF(2*n); c = n
    print(pow(2,c,mod) if c>=0 else 0)
0