C++ PROGRAM USE THE DRIVER CODE ATTACHED BELOW // { Driver Code Starts #include using namespace std; // }Driver Code Ends class Solution { public: // Function to return a path vector consisting of vertex ids from vertex 0 to target vector shortestPath(int V, vector adj[], int target) { // Enter your code here! } }; // { Driver Code Starts int main() { int tc; cin >> tc; while (tc--) { int V, E, target; cin >> V >> E >> target; vector adj[V]; for (int i = 0; i < E; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); // adj[v].push_back(u); } // string s1; // cin>>s1; Solution obj; vector ans = obj. shortestPath(V, adj, target); for (int i = 0; i < ans.size(); i++) { cout << ans[i] << " "; } cout << endl; } return 0; } // } Driver Code Ends
C++
USE THE DRIVER CODE ATTACHED BELOW
// { Driver Code Starts
#include<bits/stdc++.h>
using namespace std;
// }Driver Code Ends
class Solution {
public:
// Function to return a path
// Enter your code here!
}
};
// { Driver Code Starts
int main() {
int tc;
cin >> tc;
while (tc--) {
int V, E, target;
cin >> V >> E >> target;
vector adj[V];
for (int i = 0; i < E; i++)
{ int u, v; cin >> u >> v;
adj[u].push_back(v);
// adj[v].push_back(u);
} // string s1;
// cin>>s1;
Solution obj;
vector ans = obj. shortestPath(V, adj, target);
for (int i = 0; i < ans.size(); i++) { cout << ans[i] << " "; } cout << endl; } return 0; } // } Driver Code Ends
Step by step
Solved in 2 steps with 1 images