Advertisement
newb_ie

Untitled

Oct 12th, 2021
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. const int maxN = 100;
  5. vector<int> adj[maxN];
  6. bool visited[maxN];
  7.  
  8. void dfs (int node) {
  9. //~ cout << " => " << node;
  10. visited[node] = true;
  11.  
  12. for (auto child : adj[node]) {
  13. if (visited[child] == false) {
  14. dfs(child);
  15. }
  16. }
  17. }
  18.  
  19. int main () {
  20. ios::sync_with_stdio(false);
  21. cin.tie(nullptr);
  22. cout.tie(nullptr);
  23. int n = 7;
  24. int m = 6;
  25. for (int i = 1; i <= m; ++i) {
  26. int u,v;
  27. cin >> u >> v;
  28. adj[u].push_back(v); //u er adj te v ke rakhtesi
  29. adj[v].push_back(u); //v er adj te u ke rakhtesi
  30. }
  31. dfs(1);
  32. }
  33.  
  34.  
  35. //~ 1 2
  36. //~ 2 4
  37. //~ 2 5
  38. //~ 1 3
  39. //~ 3 6
  40. //~ 3 7
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement