Associated Course(s):
Interview Preparation
Geeks Classes DSA

Given a directed graph, the task is to complete the method **isCyclic()** to detect if there is a cycle in the graph or not. You should not read any input from stdin/console. There are multiple test cases. For each test case, this method will be called individually.

**Input:** The first line of the input contains an integer **'T'** denoting the number of test cases. Then **'T'** test cases follow. Each test case consists of two lines. Description of testcases is as follows: The First line of each test case 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 an uni-directed 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 program you don't have to worry about input, you just have to complete the function

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

**Explanation:
Testcase 1:** In the above graph there are 2 vertices. The edges are as such among the vertices.

From graph it is clear that it contains cycle.

Author: Shubham Joshi 1

lakshmi_pandey | 72 |

abbatta7 | 68 |

Ashish Kumar Vaishy | 62 |

aman19 | 58 |

Kumar Gaurav Singh | 58 |

saumitra13325 | 612 |

ashujack | 551 |

lakshmi_pandey | 544 |

aman19 | 538 |

piyushmittal25 | 514 |

blackshadows | 5249 |

akhayrutdinov | 5111 |

Ibrahim Nash | 5087 |

Quandray | 4354 |

sanjay05 | 3668 |

Login to report an issue on this page.