Given a undirected graph, the task is to complete the method isCyclic() to detect if there is a cycle in the undirected graph or not.
The first line of the input contains an integer 'T' denoting the number of test cases. Then 'T' testcases follow. Each testcase consists of two lines. Description of testcases are as follows: The First line of each testcase contains two integers 'N' and 'M' which denotes the no of vertices and no of edges respectively. The Second line of each test case contains 'M' space separated pairs u and v denoting that there is a bidirectional edge from u to v .
The method should return 1 if there is a cycle else it should return 0.
Since this is a functional problem you don't have to worry about input, you just have to complete the function isCyclic.
1 <= T <= 100
1 <= N,M <= 100
0 <= u,v <= N-1
0 1 0 0
0 1 1 2 2 3
0 1 2 3 3 4 4 2
Testcase 1: In above first test case there is a graph with 2 vertices and 2 edges the first edge is from 0 to 1 and other edge is from 0 to 0 .
Testcase 2: In the second test case there is a graph with 3 vertices and 3 edges from 0 to 1 , 1 to 2 and 2 to 3.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.