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; int cycle_start, cycle_end; bool dfs(int v){ color[v] = 1; for(auto u : adj[v]){ if(color[u] == 0){ parent[u] = v; if(dfs(u))return true; } else if(color[u] == 1){ cycle_end = v; cycle_start = u; return true; } } color[v] = 2; return false; }