int n, e; std::vector<int> adj[200000]; std::vector<int> color; // 0 - not visited,1 = entered for visit,2 = visited std::vector<int> parent; std::vector<bool> visited; int cycle_start, cycle_end; bool dfs(int v, int par){ visited[v] = 1; for(auto u : adj[v]){ if(u == par)continue; if(visited[u] == 1){ cycle_end = v; cycle_start = u; return true; } parent[u] = v; if(dfs(u, parent[u])){ return true; } } return false; }