1. class Solution {
    2. private:
    3. vector<vector<int> > ans;
    4. vector<int> path;
    5. void DFS(int node, vector<vector<int>> &G) {
    6. if (node == G.size() - 1) {
    7. path.push_back(node);
    8. ans.push_back(path);
    9. path.pop_back();
    10. return;
    11. }
    12. path.push_back(node);
    13. for (auto i : G[node]) {
    14. DFS(i, G);
    15. }
    16. path.pop_back();
    17. }
    18. public:
    19. vector<vector<int>> allPathsSourceTarget(vector<vector<int>> &graph) {
    20. DFS(0, graph);
    21. return ans;
    22. }
    23. };