結果

問題 No.330 Eigenvalue Decomposition
ユーザー 🐬hec🐬hec
提出日時 2015-12-22 02:31:32
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 461 ms / 5,000 ms
コード長 937 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 77,784 KB
実行使用メモリ 19,964 KB
最終ジャッジ日時 2023-10-18 22:28:11
合計ジャッジ時間 4,247 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
14,356 KB
testcase_01 AC 4 ms
6,040 KB
testcase_02 AC 6 ms
6,212 KB
testcase_03 AC 122 ms
14,356 KB
testcase_04 AC 4 ms
6,040 KB
testcase_05 AC 5 ms
6,148 KB
testcase_06 AC 137 ms
13,944 KB
testcase_07 AC 3 ms
6,044 KB
testcase_08 AC 89 ms
11,224 KB
testcase_09 AC 211 ms
17,764 KB
testcase_10 AC 4 ms
6,040 KB
testcase_11 AC 67 ms
9,632 KB
testcase_12 AC 274 ms
18,632 KB
testcase_13 AC 4 ms
6,040 KB
testcase_14 AC 68 ms
9,524 KB
testcase_15 AC 17 ms
6,660 KB
testcase_16 AC 4 ms
6,040 KB
testcase_17 AC 10 ms
6,392 KB
testcase_18 AC 66 ms
8,948 KB
testcase_19 AC 4 ms
6,044 KB
testcase_20 AC 14 ms
6,628 KB
testcase_21 AC 461 ms
19,964 KB
testcase_22 AC 8 ms
6,284 KB
testcase_23 AC 20 ms
6,940 KB
testcase_24 AC 209 ms
17,964 KB
testcase_25 AC 3 ms
6,040 KB
testcase_26 AC 10 ms
6,436 KB
testcase_27 AC 8 ms
6,132 KB
testcase_28 AC 3 ms
6,040 KB
testcase_29 AC 6 ms
6,084 KB
testcase_30 AC 4 ms
6,040 KB
testcase_31 AC 4 ms
6,040 KB
testcase_32 AC 4 ms
6,040 KB
testcase_33 AC 4 ms
6,040 KB
testcase_34 AC 4 ms
6,040 KB
testcase_35 AC 4 ms
6,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cassert>
#include <queue>
#include <set>
#include <map>

using namespace std;

using pii=pair<int,int>;
set<pii> s;

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);
		s.insert(make_pair(a,b));
	}
	assert(M==(int)s.size());
	int ans=0;
	for(int v=0;v<N;++v){
		if(visited[v]) continue;
		ans++,bfs(v);
	}
	cout << ans << endl;
	return 0;
}
0