
- class Solution {
- public:
- vector<int>path;
- vector
int> >ans; - void dfs(vector
int >>& graph,int x){ - if(x==graph.size()-1){
- ans.push_back(path);
- return ;
- }
- for(int i=0;i
size();i++){ - path.push_back(graph[x][i]);
- dfs(graph,graph[x][i]);
- path.pop_back();
- }
- }
- vector
int>> allPathsSourceTarget(vectorint>>& graph) { - path.push_back(0);
- dfs(graph,0);
- return ans;
- }
- };