結果

問題 No.330 Eigenvalue Decomposition
ユーザー 🐬hec🐬hec
提出日時 2015-12-22 02:25:40
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 804 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 67,080 KB
実行使用メモリ 10,432 KB
最終ジャッジ日時 2023-10-18 22:27:41
合計ジャッジ時間 3,921 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
9,632 KB
testcase_01 AC 3 ms
6,004 KB
testcase_02 AC 6 ms
6,080 KB
testcase_03 AC 94 ms
9,632 KB
testcase_04 AC 3 ms
6,004 KB
testcase_05 AC 4 ms
6,052 KB
testcase_06 AC 110 ms
9,220 KB
testcase_07 AC 4 ms
6,004 KB
testcase_08 RE -
testcase_09 AC 172 ms
8,512 KB
testcase_10 AC 3 ms
6,004 KB
testcase_11 AC 55 ms
6,760 KB
testcase_12 AC 214 ms
9,220 KB
testcase_13 AC 3 ms
6,004 KB
testcase_14 AC 57 ms
6,952 KB
testcase_15 AC 15 ms
6,392 KB
testcase_16 AC 3 ms
6,004 KB
testcase_17 AC 8 ms
6,168 KB
testcase_18 AC 47 ms
7,504 KB
testcase_19 AC 4 ms
6,004 KB
testcase_20 AC 11 ms
6,272 KB
testcase_21 AC 258 ms
10,432 KB
testcase_22 AC 7 ms
6,072 KB
testcase_23 AC 16 ms
6,324 KB
testcase_24 AC 170 ms
8,280 KB
testcase_25 AC 3 ms
6,004 KB
testcase_26 AC 9 ms
6,072 KB
testcase_27 AC 8 ms
6,096 KB
testcase_28 AC 3 ms
6,004 KB
testcase_29 RE -
testcase_30 AC 4 ms
6,004 KB
testcase_31 AC 3 ms
6,004 KB
testcase_32 AC 4 ms
6,004 KB
testcase_33 AC 4 ms
6,004 KB
testcase_34 AC 4 ms
6,004 KB
testcase_35 AC 4 ms
6,004 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(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