結果

問題 No.2293 無向辺 2-SAT
ユーザー kotatsugamekotatsugame
提出日時 2023-05-05 21:54:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 4,000 ms
コード長 1,103 bytes
コンパイル時間 1,305 ms
コンパイル使用メモリ 73,480 KB
実行使用メモリ 9,016 KB
最終ジャッジ日時 2023-08-15 03:50:54
合計ジャッジ時間 11,850 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 3 ms
5,108 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 84 ms
9,016 KB
testcase_04 AC 75 ms
4,956 KB
testcase_05 AC 69 ms
4,384 KB
testcase_06 AC 68 ms
4,384 KB
testcase_07 AC 28 ms
4,908 KB
testcase_08 AC 72 ms
4,996 KB
testcase_09 AC 62 ms
5,200 KB
testcase_10 AC 62 ms
4,952 KB
testcase_11 AC 78 ms
4,956 KB
testcase_12 AC 73 ms
5,176 KB
testcase_13 AC 64 ms
4,384 KB
testcase_14 AC 61 ms
4,380 KB
testcase_15 AC 59 ms
4,384 KB
testcase_16 AC 75 ms
5,056 KB
testcase_17 AC 77 ms
5,236 KB
testcase_18 AC 75 ms
4,932 KB
testcase_19 AC 36 ms
4,384 KB
testcase_20 AC 79 ms
4,960 KB
testcase_21 AC 77 ms
4,908 KB
testcase_22 AC 79 ms
5,044 KB
testcase_23 AC 79 ms
5,108 KB
testcase_24 AC 79 ms
5,236 KB
testcase_25 AC 79 ms
5,176 KB
testcase_26 AC 79 ms
5,016 KB
testcase_27 AC 79 ms
5,300 KB
testcase_28 AC 80 ms
5,056 KB
testcase_29 AC 80 ms
5,252 KB
testcase_30 AC 81 ms
5,112 KB
testcase_31 AC 81 ms
5,016 KB
testcase_32 AC 74 ms
4,936 KB
testcase_33 AC 73 ms
4,904 KB
testcase_34 AC 73 ms
5,104 KB
testcase_35 AC 72 ms
5,000 KB
testcase_36 AC 74 ms
5,008 KB
testcase_37 AC 74 ms
5,204 KB
testcase_38 AC 73 ms
5,080 KB
testcase_39 AC 76 ms
4,988 KB
testcase_40 AC 76 ms
5,068 KB
testcase_41 AC 68 ms
4,920 KB
testcase_42 AC 73 ms
5,096 KB
testcase_43 AC 74 ms
5,172 KB
testcase_44 AC 75 ms
4,912 KB
testcase_45 AC 76 ms
4,912 KB
testcase_46 AC 79 ms
4,896 KB
testcase_47 AC 78 ms
4,936 KB
testcase_48 AC 78 ms
4,936 KB
testcase_49 AC 77 ms
4,932 KB
testcase_50 AC 79 ms
4,924 KB
testcase_51 AC 77 ms
5,040 KB
testcase_52 AC 78 ms
5,060 KB
testcase_53 AC 79 ms
5,044 KB
testcase_54 AC 79 ms
5,300 KB
testcase_55 AC 79 ms
5,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
int N,Q;
int pr[4<<17];
vector<int>hist;
int find(int u)
{
	if(pr[u]>=0)return pr[u]=find(pr[u]);
	else return u;
}
bool merge(int u,int v)
{
	u=find(u);
	v=find(v);
	if(u==v)return false;
	if(-pr[u]<-pr[v])swap(u,v);
	pr[u]+=pr[v];
	pr[v]=u;
	hist.push_back(u);
	hist.push_back(v);
	return true;
}
void clear()
{
	for(int u:hist)pr[u]=-1;
	hist.clear();
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N>>Q;
	for(int i=0;i<N+N;i++)pr[i]=-1;
	int cnt=2*N;
	const mint inv2=mint::raw(2).inv();
	const mint all=mint::raw(2).pow(N);
	mint now=all;
	for(;Q--;)
	{
		int op;cin>>op;
		if(op==1)
		{
			int u,v;cin>>u>>v;u--,v--;
			if(merge(u,v))
			{
				if(merge(u+N,v+N))now*=inv2;
				else
				{
					now=mint::raw(0);
				}
			}
		}
		else if(op==2)
		{
			int u,v;cin>>u>>v;u--,v--;
			if(merge(u,v+N))
			{
				if(merge(u+N,v))now*=inv2;
				else
				{
					now=mint::raw(0);
				}
			}
		}
		else
		{
			clear();
			now=all;
		}
		cout<<now.val()<<"\n";
	}
}
0