結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー daiotadaiota
提出日時 2023-08-12 14:49:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 968 bytes
コンパイル時間 1,731 ms
コンパイル使用メモリ 175,700 KB
実行使用メモリ 12,672 KB
最終ジャッジ日時 2024-04-30 07:16:38
合計ジャッジ時間 3,565 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 14 ms
6,944 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 15 ms
6,944 KB
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
	}
}

int 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,k;

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

	init(2*N);

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

	map<int,int> m;
	for(i=1;i<=2*N;i++){
		m[par[i]]++;
	}

	int s=0;
	for(auto x:m){
		s+=x.second%2;
	}


	cout << s/2 << endl;



	return 0;
}
0