結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー daiotadaiota
提出日時 2023-08-12 16:04:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 971 bytes
コンパイル時間 1,727 ms
コンパイル使用メモリ 176,240 KB
実行使用メモリ 12,544 KB
最終ジャッジ日時 2024-04-30 10:47:15
合計ジャッジ時間 3,404 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 70 ms
10,240 KB
testcase_04 AC 41 ms
11,392 KB
testcase_05 AC 21 ms
6,940 KB
testcase_06 AC 57 ms
10,624 KB
testcase_07 AC 19 ms
6,940 KB
testcase_08 AC 74 ms
12,544 KB
testcase_09 AC 27 ms
6,940 KB
testcase_10 AC 64 ms
9,216 KB
testcase_11 AC 58 ms
9,088 KB
testcase_12 AC 44 ms
8,448 KB
testcase_13 AC 16 ms
6,940 KB
testcase_14 AC 31 ms
6,944 KB
testcase_15 AC 14 ms
6,944 KB
testcase_16 AC 39 ms
6,944 KB
testcase_17 AC 8 ms
6,944 KB
testcase_18 AC 48 ms
9,600 KB
testcase_19 AC 40 ms
10,752 KB
testcase_20 AC 15 ms
6,948 KB
testcase_21 AC 21 ms
6,940 KB
testcase_22 AC 10 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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[find(i)]++;
	}

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


	cout << s/2 << endl;



	return 0;
}
0