forked from abeaumont/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe.cc
More file actions
30 lines (30 loc) · 558 Bytes
/
e.cc
File metadata and controls
30 lines (30 loc) · 558 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// https://atcoder.jp/contests/abc126/tasks/abc126_e
#include<bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,u,v,z;
cin>>n>>m;
vvi g(n);
for(int i=0;i<m;i++){
cin>>u>>v>>z;
u--;v--;
g[u].push_back(v);
g[v].push_back(u);
}
vi c(n);
function<void(int,int)>dfs=[&](int u,int k){
c[u]=k;
for(int v:g[u])
if(!c[v])
dfs(v,k);
};
int k=1;
for(int i=0;i<n;i++)
if(!c[i])
dfs(i,k++);
cout<<k-1<<"\n";
}