結果

問題 No.2293 無向辺 2-SAT
ユーザー cyk203cyk203
提出日時 2023-05-05 22:27:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 4,000 ms
コード長 3,253 bytes
コンパイル時間 2,343 ms
コンパイル使用メモリ 166,772 KB
実行使用メモリ 11,980 KB
最終ジャッジ日時 2023-08-15 05:00:35
合計ジャッジ時間 13,467 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,608 KB
testcase_01 AC 3 ms
9,584 KB
testcase_02 AC 3 ms
7,752 KB
testcase_03 AC 60 ms
11,836 KB
testcase_04 AC 61 ms
11,872 KB
testcase_05 AC 55 ms
11,752 KB
testcase_06 AC 53 ms
11,732 KB
testcase_07 AC 40 ms
9,596 KB
testcase_08 AC 58 ms
11,788 KB
testcase_09 AC 58 ms
11,748 KB
testcase_10 AC 57 ms
11,776 KB
testcase_11 AC 66 ms
11,836 KB
testcase_12 AC 59 ms
11,980 KB
testcase_13 AC 45 ms
9,756 KB
testcase_14 AC 41 ms
9,584 KB
testcase_15 AC 37 ms
9,608 KB
testcase_16 AC 66 ms
11,736 KB
testcase_17 AC 63 ms
11,728 KB
testcase_18 AC 63 ms
11,760 KB
testcase_19 AC 29 ms
10,836 KB
testcase_20 AC 65 ms
11,976 KB
testcase_21 AC 64 ms
11,736 KB
testcase_22 AC 69 ms
11,752 KB
testcase_23 AC 69 ms
11,760 KB
testcase_24 AC 69 ms
11,804 KB
testcase_25 AC 70 ms
11,772 KB
testcase_26 AC 70 ms
11,836 KB
testcase_27 AC 66 ms
11,756 KB
testcase_28 AC 66 ms
11,808 KB
testcase_29 AC 66 ms
11,840 KB
testcase_30 AC 65 ms
11,756 KB
testcase_31 AC 68 ms
11,752 KB
testcase_32 AC 52 ms
11,736 KB
testcase_33 AC 52 ms
11,816 KB
testcase_34 AC 54 ms
11,752 KB
testcase_35 AC 54 ms
11,732 KB
testcase_36 AC 53 ms
11,752 KB
testcase_37 AC 56 ms
11,732 KB
testcase_38 AC 56 ms
11,732 KB
testcase_39 AC 54 ms
11,840 KB
testcase_40 AC 58 ms
11,756 KB
testcase_41 AC 41 ms
11,728 KB
testcase_42 AC 46 ms
11,768 KB
testcase_43 AC 52 ms
11,912 KB
testcase_44 AC 56 ms
11,792 KB
testcase_45 AC 59 ms
11,732 KB
testcase_46 AC 60 ms
11,836 KB
testcase_47 AC 62 ms
11,732 KB
testcase_48 AC 65 ms
11,756 KB
testcase_49 AC 68 ms
11,764 KB
testcase_50 AC 65 ms
11,760 KB
testcase_51 AC 65 ms
11,852 KB
testcase_52 AC 66 ms
11,752 KB
testcase_53 AC 64 ms
11,744 KB
testcase_54 AC 66 ms
11,752 KB
testcase_55 AC 66 ms
11,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* 
 * Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define per(i,a,b) for(ll i=(a);i>=(b);i--)
#define re(i,a,b) for(ll i=(a);i<(b);i++)
#define pe(i,a,b) for(ll i=(a);i>(b);i--)
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
template <typename T>
inline void read(T& r) {
	r=0;bool w=0; char ch=getchar();
	while(ch<'0'||ch>'9') w=ch=='-'?1:0,ch=getchar();
	while(ch>='0'&&ch<='9') r=r*10+(ch^48), ch=getchar();
	r=w?-r:r;
}
template <typename T>
inline void readupp(T& r){
	r=0;
	char ch=getchar();
	while(ch>'Z'||ch<'A')ch=getchar();
	r=ch;
}
template <typename T>
inline void readlow(T& r){
	r=0;
	char ch=getchar();
	while(ch>'z'||ch<'a')ch=getchar();
	r=ch;
}
template <typename T>
inline void readdig(T& r){
	r=0;
	char ch=getchar();
	while(ch>'9'||ch<'0')ch=getchar();
	r=ch-'0';
}
template <typename T>
inline void readvisi(T& r){
	r=0;
	char ch=getchar();
	while(ch>126||ch<33)ch=getchar();
	r=ch;
}
template <typename T>
inline ll readlowstr(T& r){
	ll n=0;
	char ch=getchar();
	while(ch>'z'||ch<'a')ch=getchar();
	while(ch<='z'&&ch>='a')r[++n]=ch-'a',ch=getchar();
	return n;
}
template <typename T>
inline ll readuppstr(T& r){
	ll n=0;
	char ch=getchar();
	while(ch>'Z'||ch<'A')ch=getchar();
	while(ch<='Z'&&ch>='A')r[++n]=ch-'A',ch=getchar();
	return n;
}
template <typename T>
inline ll readdigstr(T& r){
	ll n=0;
	char ch=getchar();
	while(ch>'9'||ch<'0')ch=getchar();
	while(ch<='9'&&ch>='0')r[++n]=ch-'0',ch=getchar();
	return n;
}
template <typename T>
inline ll readvisistr(T& r){
	ll n=0;
	char ch=getchar();
	while(ch>126||ch<33)ch=getchar();
	while(ch<=126&&ch>=33)r[++n]=ch,ch=getchar();
	return n;
}
const ll MOD=998244353;
ll gcd(ll A,ll B){return B?gcd(B,A%B):A;}
template<typename T>
void chkmax(T&A,T B){if(A<B)A=B;}
template<typename T>
void chkmin(T&A,T B){if(A>B)A=B;}
template<typename T>
T Madd(T A,T B){return A+B>=MOD?A+B-MOD:A+B;}
template<typename T>
T Msub(T A,T B){return A-B<0?A-B+MOD:A-B;}
template<typename T>
void MODed(T &A){A%=MOD;A+=(A<0?MOD:0);}
ll pw(ll A,ll B){
	ll res=1;
	while(B){
		if(B&1)res=res*A%MOD;
		A=A*A%MOD;
		B>>=1;
	}
	return res;
}
void _FILE(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}
const ll N=200003,M=3003,INF=2000000000000000007ll;
ll n,q,id[N*2],t,q1[N],q2[N];
ll find(ll x){return x==id[x]?x:id[x]=find(id[x]);}
void unite(ll x,ll y){id[find(x)]=find(y);}
int main(){
	read(n),read(q);
	rep(i,1,2*n)id[i]=i;
	t=n;
	ll lst=0;
	rep(i,1,q){
		ll in1,in2,in3;
		read(in1);
		if(in1==1){
			read(in2),read(in3);
			q1[i]=in2,q2[i]=in3;
			if(find(in2)==find(in3));
			else if(find(in2)==find(in3+n))t=-1;
			else unite(in2,in3),unite(in2+n,in3+n),t--;
		}
		if(in1==2){
			read(in2),read(in3);
			q1[i]=in2,q2[i]=in3;
			if(find(in2)==find(in3+n));
			else if(find(in2)==find(in3))t=-1;
			else unite(in2,in3+n),unite(in3,in2+n),t--;
		}
		if(in1==3){
			t=n;
			rep(j,lst+1,i-1)id[q1[j]]=q1[j],id[q1[j]+n]=q1[j]+n,id[q2[j]]=q2[j],id[q2[j]+n]=q2[j]+n;
			lst=i;
		}
		if(t<0)puts("0");
		else printf("%lld\n",pw(2,t));
	}
	return 0;
}
0