#include #include #include #include using namespace std; class Graph{ private: int numofvertices; list *ptr; vector color; vector root; int startofcircle, endofcircle; bool DFS(int v) { color[v]=1; for(int u: ptr[v]){ if(color[u]==0) { root[u]=v; if(DFS(u)) return true; } else if(color[u]==1) { endofcircle=v; startofcircle=u; return true; } } color[v]=2; return false; } public: Graph(int V): numofvertices(V) { ptr=new list[numofvertices]; } ~Graph() { delete [] ptr;} void addEdge (int u, int v) { ptr[u].push_back(v); } bool cycle(vector &cycle) { color.assign(numofvertices, 0); root.assign(numofvertices, -1); startofcircle=-1; for(int v=0; v