結果

問題 No.330 Eigenvalue Decomposition
ユーザー 🐬hec🐬hec
提出日時 2015-12-22 01:03:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 261 ms / 5,000 ms
コード長 806 bytes
コンパイル時間 1,033 ms
コンパイル使用メモリ 66,892 KB
実行使用メモリ 10,444 KB
最終ジャッジ日時 2023-10-18 22:20:19
合計ジャッジ時間 4,858 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
9,644 KB
testcase_01 AC 3 ms
6,016 KB
testcase_02 AC 5 ms
6,092 KB
testcase_03 AC 94 ms
9,644 KB
testcase_04 AC 3 ms
6,016 KB
testcase_05 AC 4 ms
6,064 KB
testcase_06 AC 110 ms
9,232 KB
testcase_07 AC 3 ms
6,016 KB
testcase_08 AC 73 ms
8,128 KB
testcase_09 AC 172 ms
8,524 KB
testcase_10 AC 3 ms
6,016 KB
testcase_11 AC 55 ms
6,772 KB
testcase_12 AC 213 ms
9,232 KB
testcase_13 AC 3 ms
6,016 KB
testcase_14 AC 57 ms
6,964 KB
testcase_15 AC 14 ms
6,404 KB
testcase_16 AC 3 ms
6,016 KB
testcase_17 AC 8 ms
6,180 KB
testcase_18 AC 48 ms
7,516 KB
testcase_19 AC 3 ms
6,016 KB
testcase_20 AC 12 ms
6,284 KB
testcase_21 AC 261 ms
10,444 KB
testcase_22 AC 7 ms
6,084 KB
testcase_23 AC 17 ms
6,336 KB
testcase_24 AC 170 ms
8,292 KB
testcase_25 AC 3 ms
6,016 KB
testcase_26 AC 9 ms
6,084 KB
testcase_27 AC 8 ms
6,108 KB
testcase_28 AC 4 ms
6,016 KB
testcase_29 AC 6 ms
6,060 KB
testcase_30 AC 4 ms
6,016 KB
testcase_31 AC 3 ms
6,016 KB
testcase_32 AC 3 ms
6,016 KB
testcase_33 AC 4 ms
6,016 KB
testcase_34 AC 3 ms
6,016 KB
testcase_35 AC 3 ms
6,016 KB
権限があれば一括ダウンロードができます

ソースコード

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,c;
		cin >> a >> b >> c;
		assert(1<=a&&a<=N);
		assert(1<=b&&b<=N);
		assert(1<=c&&c<=1000000000);
		graph[a-1].push_back(b-1);
		graph[b-1].push_back(a-1);
	}
	int ans=0;
	for(int v=0;v<N;++v){
		if(visited[v]) continue;
		ans++,bfs(v);
	}
	cout << ans << endl;
	return 0;
}
0