Associated Course(s):
Interview Preparation
Geeks Classes DSA

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.

**Input:**

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** .

**Output:**

The method should return **1** if there is a cycle else it should return **0**.

**User task:**

Since this is a functional problem you don't have to worry about input, you just have to complete the function **isCyclic.**

**Constraints:**

1 <= T <= 100

1 <= N,M <= 100

0 <= u,v <= N-1

**Example:
Input:**

2

2 2

0 1 0 0

4 3

0 1 1 2 2 3

1

0

Testcase 1:

Author: Shubham Joshi 1

may55 | 86 |

ashujack | 84 |

aman19 | 82 |

abbatta7 | 75 |

lakshmi_pandey | 74 |

saumitra13325 | 648 |

ashujack | 591 |

aman19 | 562 |

lakshmi_pandey | 546 |

aroma17 | 535 |

blackshadows | 5249 |

akhayrutdinov | 5111 |

Ibrahim Nash | 5087 |

Quandray | 4354 |

sanjay05 | 3668 |

Login to report an issue on this page.