
g = 1 and s = 0
Now in this land, there is a path from 1 to 0 through town 4 which is the minimum path. Hence the answer is 2.
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, ‘V’ and ‘E’, denoting the number of towns and roads.
The next ‘E’ lines of the test case contain two space-separated integers, ‘a’ and ‘b’, denoting a road between ‘a’ and ‘b’.
The last line of the test case contains two space-separated integers, ‘g’ and ‘s’, denoting Genos’s and Saitama’s town.
For each test case, print the number of minimum roads taken to get from ‘g’ to ‘s’.
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.
If there is no way to reach Saitama, return -1.
1 <= T <= 10
1 <= V <= 1000
1 <= E <= (V * (V - 1)) / 2
0 <= g, s <= V-1
Time Limit: 1sec
In this approach, iterate through the whole graph using BFS and whenever you encounter a new level of nodes, update the count by 1.
The steps are as follows :