Want to solve this problem? Login now to get access to solve the problems
There are no self-loops(an edge connecting the vertice to itself) in the given graph.
The first line of input will contain three integers V, E, and S, separated by a single space. From the second line onwards, the next 'E' lines will denote the edge of the graphs. Every edge is defined by two single space-separated integers 'a' and 'b', which signifies an edge between vertice 'a' and vertice 'b'.
The single line contains an string, "True" if cycle exists, else "False".
1 <= V <= 10^5 0 <= E <= 2 * 10^5 0 <= u,v < V Time Limit: 1sec
4 4 0 1 1 2 2 3 3 0
From node 0 we can reach 0 again by following this sequence of nodes in the path: 0,1,2,3,0. Similarly from any of the node we can reach again to that node by following a path. The graph in itself is a cycle.
5 3 0 1 1 2 3 4