Path Reversals Problem Statement
You are provided with a directed graph and two nodes, 'S' and 'D'. Your objective is to determine the minimum number of edges that need to be reversed to establish a path from node 'S' to node 'D'.
Input:
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains two space-separated integers, 'N' and 'M', representing the number of nodes and edges in the graph.
The following M lines of the test case contain two space-separated integers, 'A' and 'B', representing an edge from node 'A' to node 'B'.
The last line of the test case contains two space-separated integers, 'S' and 'D', denoting the start and end node.
Output:
For each test case, output a single integer, which is the minimum number of edges that need to be reversed to create a path from 'S' to 'D'.
Each test case's result should be printed on a new line.
Example:
Consider 'S' = 0 and 'D' = 4. In the given graph, a path from node 0 to node 4 can be achieved by reversing only the edge (0, 5). Therefore, the answer is 1.
Constraints:
- 1 <= T <= 5
- 2 <= N <= 105
- N - 1 <= M <= 105
- 0 <= A, B < N
- 0 <= S, D < N
- Time Limit: 1 sec
Note:
There is no need to print anything, as it is already handled. Simply implement the function and return the result.
AnswerBot
1y
The task is to find the minimum number of edges that need to be reversed in a directed graph to find the path from a start node to an end node.
The problem can be solved using graph traversal algorithm...read more
Help your peers!
Add answer anonymously...
Top Myntra Mern Stack Developer interview questions & answers
Popular interview questions of Mern Stack Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app