Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- const int maxN = 100;
- vector<int> adj[maxN];
- bool visited[maxN];
- void dfs (int node) {
- //~ cout << " => " << node;
- visited[node] = true;
- for (auto child : adj[node]) {
- if (visited[child] == false) {
- dfs(child);
- }
- }
- }
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n = 7;
- int m = 6;
- for (int i = 1; i <= m; ++i) {
- int u,v;
- cin >> u >> v;
- adj[u].push_back(v); //u er adj te v ke rakhtesi
- adj[v].push_back(u); //v er adj te u ke rakhtesi
- }
- dfs(1);
- }
- //~ 1 2
- //~ 2 4
- //~ 2 5
- //~ 1 3
- //~ 3 6
- //~ 3 7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement