結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
15,968 KB
testcase_01 AC 3 ms
6,028 KB
testcase_02 AC 6 ms
6,232 KB
testcase_03 AC 125 ms
15,968 KB
testcase_04 AC 4 ms
6,028 KB
testcase_05 AC 5 ms
6,152 KB
testcase_06 AC 139 ms
15,492 KB
testcase_07 AC 4 ms
6,032 KB
testcase_08 AC 91 ms
12,236 KB
testcase_09 AC 214 ms
20,916 KB
testcase_10 AC 3 ms
6,028 KB
testcase_11 AC 68 ms
10,608 KB
testcase_12 AC 272 ms
21,744 KB
testcase_13 AC 4 ms
6,028 KB
testcase_14 AC 68 ms
10,360 KB
testcase_15 AC 15 ms
6,728 KB
testcase_16 AC 3 ms
6,028 KB
testcase_17 AC 10 ms
6,444 KB
testcase_18 AC 58 ms
9,404 KB
testcase_19 AC 3 ms
6,032 KB
testcase_20 AC 13 ms
6,720 KB
testcase_21 AC 427 ms
23,064 KB
testcase_22 AC 8 ms
6,340 KB
testcase_23 AC 20 ms
7,120 KB
testcase_24 AC 211 ms
21,124 KB
testcase_25 AC 3 ms
6,028 KB
testcase_26 AC 10 ms
6,544 KB
testcase_27 AC 8 ms
6,120 KB
testcase_28 AC 4 ms
6,028 KB
testcase_29 AC 5 ms
6,072 KB
testcase_30 AC 3 ms
6,028 KB
testcase_31 AC 4 ms
6,028 KB
testcase_32 AC 3 ms
6,028 KB
testcase_33 AC 3 ms
6,028 KB
testcase_34 AC 4 ms
6,028 KB
testcase_35 AC 4 ms
6,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;
using ll =long long;

using pii=pair<ll,ll>;
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){
	ll N,M;
	cin >>  N >> M;
	assert(1LL<=N&&N<=100000LL);
	assert(0LL<=M&&M<=min(1LL*N*(N-1)/2,200000LL));
	for(int loop=0;loop<M;++loop){
		ll a,b,c;
		cin >> a >> b >> c;
		assert(1LL<=a&&a<b&&b<=N);
		assert(1LL<=c&&c<=1000000000LL);
		graph[a-1].push_back(b-1);
		graph[b-1].push_back(a-1);
		s.insert(make_pair(a,b));
	}
	assert(M==(ll)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