Detect Cycle in a Directed Graph
The first line of input contains an integer T, the number of test cases. The first line of each test case contains two single space-separated integers ‘V’, and ‘E’. ‘V’ represents the number of nodes and ‘E’ represents the number of edges in the graph. From the second line onwards of each test case, the next 'E' lines will denote the edges of the graph where every edge is defined by two single space-separated integers 'A' and 'B', which signifies an edge from vertex 'A’ to vertex 'B'.
For each test case print "true" if a cycle exists, else "false".
1 <= T <= 10 1 <= V <= 10^3 0 <= E <= 10^3 0 <= A, B < V Time Limit: 1 sec
Distance to a Cycle in Undirected Graph