You are given an undirected graph, a source vertex, and an integer k. Check if there is any simple path(without any cycle) from source to any vertex such that its distance is greater than 'k'.
Path in a graph is a finite or infinite sequence of edges that joins a sequence of vertices that are all distinct.
The first line contains four integers 'n', 'm', 's', and 'k' where 'n' is the number of vertices, 'm' is the no of edges, and 's' is the source vertex.
The next 'm' lines describe the edge. Each edge is characterized by three integers a, b, and c where a and b denote the endpoints of the edge and c the length of the edge.
The edges[i][0] ,edges[i][1] contains the vertex that is connected to the edge. The edges[i][2] contains the length of edge for all 0<i<m.
Output Format :
Return true if there is any such path otherwise false.
Note :
Graph does not contain self-loops.
1 <= 'n' <= 10
1 <= 'm' <= min(n*(n-1))/2,100)
0 <= 'a', 'b', 's' <= n-1
1 <= ci, k <= 1000000
For all 1 <= i <= m
Time Limit: 1 sec
6 6 0 23
0 1 5
1 2 4
2 3 5
3 4 5
4 5 5
0 5 1
true
The graph will be :

One of the longer paths from 0 to 5 will be from the vertex 0->1->2->3->4->5.
Adding the edge weights, we get 5+4+5+5+5=24 which is greater than 23. Hence we return true.
4 3 1 25
0 1 1
0 2 2
2 3 3
false
Use backtracking from the source vertex to find all the paths.
The key idea will be to find all possible paths and check their path length. If the path length is greater than βkβ we return true. If no path has a weight greater than βkβ we return false.
The algorithm is as follows:
From the source vertex all the paths and check if the total distance is greater than βkβ.
O(N!), where βNβ is no of vertices in the given graph.
There are total N! paths in the graph in the worse case and checking for each path takes n time hence time complexity is O(N!)
O(N), where βNβ is no of vertices in the given graph.
We create a visited array of size βNβ to keep track of vertices in the path.