dfs(strt); void dfs(int node) { ///This segment works to return if goal acheived. (Main modification of Standerd algo). if(get_goal) return; if(node==goal) { path.push_back(node); get_goal=true; return; } vis[node]=1; path.push_back(node); for(int i=1;i<=n;i++) { if(graph[node][i] && !vis[i]) { dfs(i); } } }