結果

問題 No.2202 贅沢てりたまチキン
ユーザー daiotadaiota
提出日時 2023-02-04 03:04:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 965 bytes
コンパイル時間 1,434 ms
コンパイル使用メモリ 165,932 KB
実行使用メモリ 5,732 KB
最終ジャッジ日時 2023-09-15 23:52:39
合計ジャッジ時間 4,864 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 RE -
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 18 ms
5,732 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 29 ms
4,376 KB
testcase_23 AC 32 ms
4,376 KB
testcase_24 AC 31 ms
4,376 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(int i=0;i<int(n);i++)


int par[200010],rk[200010],sz[200010];

void init(int n){

	REP(i,n+1){
		par[i]=i;
		rk[i]=0;
		sz[i]=1;
	}
}

ll find(int x){

	if(par[x]==x){
	   return x;
	}else{
	  return par[x]=find(par[x]);
	}
}

void unite(int x,int y){

	x=find(x); y=find(y);
	if(x==y) return;

	if(rk[x]<rk[y]){
		par[x]=y;
		sz[y]=sz[x]+sz[y];
	}else{
		par[y]=x;
		sz[x]=sz[x]+sz[y];
		if(rk[x]==rk[y]) rk[x]++;
	}
}

bool same(int x,int y){

	return find(x)==find(y);
}

int size(int x){

	return sz[find(x)];
}


int main(void){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
	int i,j;

	int N,M;
	cin >> N >> M;

	init(2*N);
	for(i=1;i<=M;i++){
		int a,b;
		cin >> a >> b;
		unite(a,b+N);
		unite(a+N,b);
	}

	for(i=1;i<=N;i++){
		if(!same(i,i+N)){
			cout << "No" << endl;
			return 0;
		}
	}


	cout << "Yes" << endl;


	return 0;
}
0