1. class Solution {
    2. public:
    3. vector<vector<int>> result;
    4. vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
    5. vector<int>path;
    6. dfs(graph,path,0);
    7. return result;
    8. }
    9. void dfs(vector<vector<int>>& graph,vector<int>& path,int s){
    10. path.emplace_back(s);
    11. if(s==graph.size()-1){
    12. result.emplace_back(path);
    13. path.pop_back();
    14. return;
    15. }
    16. for(auto p:graph[s]){
    17. dfs(graph,path,p);
    18. }
    19. path.pop_back();
    20. }
    21. };