結果

問題 No.330 Eigenvalue Decomposition
ユーザー 🐬hec🐬hec
提出日時 2015-12-19 16:50:29
言語 C++11
(gcc 13.3.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 802 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 66,252 KB
実行使用メモリ 6,016 KB
最終ジャッジ日時 2024-09-16 16:07:50
合計ジャッジ時間 5,892 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 RE * 4
other AC * 4 RE * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cassert>
#include <queue>
using namespace std;

const int vmax=100010;
vector<int> graph[vmax];
bool visited[vmax];

void bfs(int v){
	visited[v]=true;
	queue<int> q;
	q.push(v);
	while(!q.empty()){
		int cur=q.front();q.pop();
		for(auto &nxt:graph[cur]){
			if(visited[nxt]) continue;
			visited[nxt]=true;
			q.push(nxt);
		}
	}
	return ;
}

int main(void){
	int N,M;
	cin >>  N >> M;
	assert(1<=N&&N<=100000);
	assert(0<=M&&M<=200000);
	for(int loop=0;loop<M;++loop){
		int a,b;
		cin >> a >> b;
		assert(1<=a&&a<b&&b<=N);
		graph[a-1].push_back(b-1);
		graph[b-1].push_back(a-1);
	}
	
	int dummy;
	cin >> dummy;
	assert(cin.eof());
	
	int ans=0;
	for(int v=0;v<N;++v){
		if(visited[v]) continue;
		ans++,bfs(v);
	}
	cout << ans << endl;
	return 0;
}
0