| 3 | using namespace std; |
| 4 | |
| 5 | bool cycleBFS(int node, vector<int> &vis, vector<int> arr[]) |
| 6 | { |
| 7 | queue<pair<int, int>> q; |
| 8 | q.push({node, -1}); |
| 9 | vis[node] = 1; |
| 10 | while (!q.empty()) |
| 11 | { |
| 12 | int n = q.front().first; |
| 13 | int p = q.front().second; |
| 14 | q.pop(); |
| 15 | for (auto i : arr[n]) |
| 16 | { |
| 17 | if (vis[i] == 0) |
| 18 | { |
| 19 | vis[i] = 1; |
| 20 | q.push({i, n}); |
| 21 | } |
| 22 | else |
| 23 | { |
| 24 | if (i != p) |
| 25 | return true; |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | return false; |
| 30 | } |
| 31 | |
| 32 | bool cycleDFS(int node, int parent, vector<int> &vis, vector<int> arr[]) |
| 33 | { |