Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void dfs (vector<vector<int>>& graph, vector <int> &path , vector < vector <int> > &res, int src , int dis, vector <bool> &vis )
- {
- path.push_back (src);
- if (src == dis)
- {
- res.push_back (path);
- return;
- }
- for (int i = 0 ; i < graph[src].size(); i++ )
- {
- int cur = graph[src][i];
- if (!vis[cur])
- {
- vis [cur] = true;
- dfs (graph, path, res, cur, dis, vis);
- if (path.size())
- path.pop_back();
- vis[cur] = false;
- }
- }
- }
- vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
- vector < vector <int> > res;
- vector <int> path;
- vector <bool> vis (graph.size(), false);
- dfs (graph , path, res, 0 , graph.size() - 1, vis );
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement