Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unordered_map<int,vector<int>> adj;
- vector<int> vis;
- void dfs(int root){
- vis[root] = 1;
- for(int v : adj[root]){
- if(vis[v] == 0)dfs(v);
- }
- }
- int main(){
- int cnt =0;
- for(int node = 0;node < n; node++){
- if(vis[node] == 0){
- dfs(node);
- cnt++;
- }
- }
- cout << "Connected components : " << cnt ;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement