| 14 | } |
| 15 | |
| 16 | bool bfs_find(vector<int> vec[], vector<bool> &visited, vector<int> &parent, int source) |
| 17 | { |
| 18 | queue<int> q; |
| 19 | q.push(source); |
| 20 | visited[source] = true; |
| 21 | while (q.empty() == false) |
| 22 | { |
| 23 | int curr = q.front(); |
| 24 | q.pop(); |
| 25 | for (int i = 0; i < vec[curr].size(); i++) |
| 26 | { |
| 27 | int adjacent = vec[curr][i]; |
| 28 | if (visited[adjacent] == false) |
| 29 | { |
| 30 | visited[adjacent] = true; |
| 31 | q.push(adjacent); |
| 32 | parent[adjacent] = curr; |
| 33 | } |
| 34 | else if (visited[adjacent] == true && parent[curr] != adjacent) |
| 35 | { |
| 36 | return true; |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | bool bfs_rec(vector<int> vec[], int v) |
| 44 | { |