Given an undirected,unweighted graph and two vertices u and v,the task is to find the path between these two vertices.u can be considered as the source vertex and v as the destination vertex.
Number of vertices-5
Number of edges-4
Given vertices are 2 and 4.
The path between 2 and 4 is 2->1->3->4.
1.DFS is called on vertex u.
2.A stack S is kept to keep track of the path between the source vertex and the current vertex.
3.As soon as destination vertex v is encountered,we return the path as the contents of the stack.
using namespace std;
void dfs(int node)
//printing the vertices of the path
//until final vertex is reached
color[node]=2;//marking the visited nodes
// n is the number of vertices
// m is the number of edges
// u is the source vertex
// v is the destination vertex
//clearing the arrays and vectors
//a and b denote the starting and ending points of the edge
//maintaining the adjacency lists
//calling dfs on source vertex