Timer is Running

Given a graph, a source vertex in the graph and a number k, find if there is a simple path, of path length **greater then or equal to k**,(without any cycle) starting from a given source and ending at any other vertex.

Source vertex should always be 0.

**Input:**

First Line contains an integer T denoting the number of test cases. Then T test cases follow.

Each test case contains two lines. First Line contains three integers V, E and k representing vertices, edges of the graph and the required minimum length respectively. Second line contains 3 * E integers containing the information of all edges in the graph. Information of a single edge is a triplet in the following format: (Source Destination Distance). See example for more understanding.

**Output:**

For each test case print 1 if the path of atleast k distance exists, else print 0 in a new line.

**Constraints:**

1 <= T <= 30

2 <= V <= 5

1 <= E <= 20

1 <= k <= 100

**Example: **The Graph below represents only the 1st test case in the example input.

**Input:**

2

9 14 60

0 1 4 0 7 8 1 2 8 1 7 11 2 3 7 2 5 4 2 8 2 3 4 9 3 5 14 4 5 10 5 6 2 6 7 1 6 8 6 7 8 7

4 3 8

0 1 5 1 2 1 2 3 1

**Output:**

1

0

**Explanation:**

Test Case 2: There exists no path which has a distance of 8

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.

abnandi04 | 801 |

KshamaGupta | 412 |

srivastavad270 | 223 |

bhavyapratap56 | 206 |

anshusingh20112001 | 181 |

abnandi04 | 776 |

KshamaGupta | 296 |

srivastavad270 | 223 |

bhavyapratap56 | 206 |

afreensartaj131 | 170 |

blackshadows | 5362 |

Ibrahim Nash | 5244 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4748 |

Login to report an issue on this page.