結果

問題 No.330 Eigenvalue Decomposition
ユーザー 🐬hec🐬hec
提出日時 2015-12-22 02:27:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 258 ms / 5,000 ms
コード長 813 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 67,172 KB
実行使用メモリ 10,452 KB
最終ジャッジ日時 2023-10-18 22:27:45
合計ジャッジ時間 3,445 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
9,652 KB
testcase_01 AC 3 ms
6,024 KB
testcase_02 AC 5 ms
6,100 KB
testcase_03 AC 94 ms
9,652 KB
testcase_04 AC 4 ms
6,024 KB
testcase_05 AC 5 ms
6,072 KB
testcase_06 AC 110 ms
9,240 KB
testcase_07 AC 3 ms
6,024 KB
testcase_08 AC 73 ms
8,136 KB
testcase_09 AC 172 ms
8,532 KB
testcase_10 AC 3 ms
6,024 KB
testcase_11 AC 56 ms
6,780 KB
testcase_12 AC 213 ms
9,240 KB
testcase_13 AC 4 ms
6,024 KB
testcase_14 AC 57 ms
6,972 KB
testcase_15 AC 14 ms
6,412 KB
testcase_16 AC 3 ms
6,024 KB
testcase_17 AC 8 ms
6,188 KB
testcase_18 AC 46 ms
7,524 KB
testcase_19 AC 4 ms
6,024 KB
testcase_20 AC 11 ms
6,292 KB
testcase_21 AC 258 ms
10,452 KB
testcase_22 AC 7 ms
6,092 KB
testcase_23 AC 16 ms
6,344 KB
testcase_24 AC 170 ms
8,300 KB
testcase_25 AC 4 ms
6,024 KB
testcase_26 AC 9 ms
6,092 KB
testcase_27 AC 8 ms
6,116 KB
testcase_28 AC 4 ms
6,024 KB
testcase_29 AC 5 ms
6,068 KB
testcase_30 AC 4 ms
6,024 KB
testcase_31 AC 3 ms
6,024 KB
testcase_32 AC 3 ms
6,024 KB
testcase_33 AC 3 ms
6,024 KB
testcase_34 AC 4 ms
6,024 KB
testcase_35 AC 4 ms
6,024 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<=min<int>(1LL*N*(N-1)/2,200000));
	for(int loop=0;loop<M;++loop){
		int a,b,c;
		cin >> a >> b >> c;
		assert(1<=a&&a<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