You are given a directed graph and two vertices on it. Your task is to find if there exists a path between the first vertex to the second vertex or not.
Example
Consider the following graph:

Input to construct the above graph:
Input:
No. of nodes in graph = 4
No. of edges in graph = 5
Edges:
1 2
2 3
2 4
3 1
3 4
No. of queries = 2
1 4
4 2
Output:
Yes
No
Explanation:
For the first query, the answer is
Yes because we can construct a path as shown in the diagram below
( 1->2->4 ) but for ...
Published on October 12, 2020 14:02