| 50 | } |
| 51 | |
| 52 | void bfs(int node, vector<int> &vis, vector<int> arr[], vector<int> &ans) |
| 53 | { |
| 54 | queue<int> q; |
| 55 | q.push(node); |
| 56 | vis[node] = 1; |
| 57 | while (!q.empty()) |
| 58 | { |
| 59 | int f = q.front(); |
| 60 | q.pop(); |
| 61 | ans.push_back(f); |
| 62 | for (auto i : arr[f]) |
| 63 | { |
| 64 | if (!vis[i]) |
| 65 | { |
| 66 | vis[i] = 1; |
| 67 | q.push(i); |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | void dfs(int node, vector<int> &vis, vector<int> arr[], vector<int> &ans) |
| 74 | { |