Possible paths between 2 vertices
Submissions: 802   Accuracy:

17.89%

  Difficulty: Medium   Marks: 4

Count the total number of ways or paths that exist between two vertices in a directed graph. These paths doesn’t contain a cycle.

Input:
The first line of input contains an integer T. Then T test cases follow. Each test case contains two integers N and M . In the next line are M space separated values u,v denoting an edge from u to v. Next line contains the starting node s and the ending node e. (The vertices start from 1)

Output: For each testcase print the total number of paths that exists between the starting and the ending node.

Constraints:
1<=T<=100
1<=N,M<=100
1<=u,v, s,e<=N

Example:
Input:

1
5 7
1 2 1 3 1 5 2 4 2 5 3 5 4 3
1 5
Output:
4

Explanation:
Testcase 1 :  There are 4 paths from 1 to 5. 
                       1 -> 5
                       1 -> 2 -> 5
                       1 -> 3 -> 5
                       1 -> 2 -> 4 -> 3 -> 5

** For More Input/Output Examples Use 'Expected Output' option **

Author: SIDG


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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.