結果
| 問題 | No.330 Eigenvalue Decomposition |
| コンテスト | |
| ユーザー |
🐬hec
|
| 提出日時 | 2015-12-22 02:44:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 472 ms / 5,000 ms |
| コード長 | 962 bytes |
| 記録 | |
| コンパイル時間 | 733 ms |
| コンパイル使用メモリ | 77,908 KB |
| 実行使用メモリ | 22,784 KB |
| 最終ジャッジ日時 | 2024-09-18 18:29:14 |
| 合計ジャッジ時間 | 4,382 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 31 |
ソースコード
#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;
}
🐬hec