
n = 5, m = 5, a = 1, b = 0
Now in this example, all the paths from ‘1’ to ‘0’ are:
1 -> 4 -> 0
1 -> 5 -> 4 -> 0
The track 4 -> 0 is present in both of these paths. Hence the answer is 1.
The first line contains a single integer ‘T’ denoting the number of test cases. Then each test case follows:
The first line of each test case contains two integers, ‘N’ and ‘M’, denoting the number of cities and tracks, respectively.
The next ‘M’ lines of the test case contain two space-separated integers, ‘x’ and ‘y’, denoting a track between ‘x’ and ‘y’.
The last line of the test case contains two space-separated integers, ‘a’ and ‘b’, denoting the starting and ending city of Thomas and his friends.
For each test case, print the total number of common tracks between all the paths from ‘a’ to ‘b’.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function and return the answer.
1 <= T <= 10
1 <= N <= 1000
N-1 <= M <= (V * (V - 1)) / 2
0 <= a, b <= V - 1
Time Limit: 1sec
In this approach, iterate through the whole graph using DFS and take three vectors inTime, low, outTime, in which we will store the first time we will visit that node, the minimum time we encountered the node and the time when we finally left the current node, respectively.
The steps are as follows :