結果

問題 No.2418 情報通だよ!Nafmoくん
ユーザー forest3forest3
提出日時 2023-09-29 16:41:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 757 bytes
コンパイル時間 3,212 ms
コンパイル使用メモリ 177,212 KB
実行使用メモリ 22,632 KB
最終ジャッジ日時 2023-09-29 16:42:03
合計ジャッジ時間 4,736 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 96 ms
21,420 KB
testcase_04 AC 31 ms
16,616 KB
testcase_05 AC 55 ms
10,440 KB
testcase_06 AC 67 ms
19,772 KB
testcase_07 AC 55 ms
8,912 KB
testcase_08 AC 74 ms
22,632 KB
testcase_09 AC 70 ms
12,396 KB
testcase_10 AC 90 ms
20,040 KB
testcase_11 AC 77 ms
18,172 KB
testcase_12 AC 54 ms
15,288 KB
testcase_13 AC 26 ms
7,720 KB
testcase_14 AC 48 ms
12,392 KB
testcase_15 AC 39 ms
4,720 KB
testcase_16 AC 111 ms
15,896 KB
testcase_17 AC 23 ms
4,752 KB
testcase_18 AC 54 ms
16,752 KB
testcase_19 AC 24 ms
15,632 KB
testcase_20 AC 44 ms
4,848 KB
testcase_21 AC 33 ms
9,356 KB
testcase_22 AC 28 ms
5,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/dsu>
using namespace atcoder;

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> g( N * 2 );
	for( int i = 0; i < M; i++ ) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back( b );
		g[b].push_back( a );
	}
	vector<int> v( N * 2 );
	dsu ds( N * 2 );
	for( int i = 0; i < N * 2; i++ ) {
		if( v[i] ) continue;
		queue<int> q;
		q.push( i );
		v[i] = 1;
		while( q.size() ) {
			int u = q.front();
			q.pop();
			for( int e : g[u] ) {
				if( v[e] ) continue;
				q.push( e );
				v[e] = 1;
				ds.merge( i, e );
			}
		}
	}
	vector<vector<int>> gg = ds.groups();
	int sz = gg.size(), ans = N;
	for( int i = 0; i < sz; i++ ) ans -= gg[i].size() / 2;
	cout << ans << endl;
 }
0