C++ || DFS || With Comments || Simple
\nclass Solution {\npublic:\n    \n    void dfs(vector<vector<int>> &graph, vector<vector<int>> &res, vector<bool> &vis, int start, int store) {\n\t\t// mark th
```\nclass Solution {\npublic:\n    \n    void dfs(vector<vector<int>> &graph, vector<vector<int>> &res, vector<bool> &vis, int start, int store) {\n\t\t// mark the current node as visited to not reach it again\n        vis[start] = true;\n\t\t\n\t\t// iterate over all the neighbours of start node\n\t\t// and if it is not visited, add it to the result list\n\t\t// make a recursive call making the current node as start \n        for (int node : graph[start]) {\n            if (!vis[node]) {\n                res[node].push_back(store);\n                dfs(graph, res, vis, node, store);\n            }\n        }\n    }\n    \n    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        // converting the edge list into an adjacency list\n        vector<vector<int>> graph(n);\n        for (auto &i : edges) {\n            graph[i[0]].push_back(i[1]);\n        }\n        \n        // here we iterate over all the nodes and check upto which nodes we can reach from the current node\n        // for example, start from 0 and check upto which nodes we can reach from 0\n        // when you reach a new node looping through the neighbours, add 0 to the result list at the index of the reached node\n        // so as to mention that we can reach this node from 0\n        vector<vector<int>> res(n);\n        for (int i = 0; i < n; ++i) {\n            vector<bool> visited(n);\n\t\t\t// mark the current node as visited to not reach it again\n            visited[i] = true;\n            dfs(graph, res, visited, i, i);\n        }\n        return res;\n    }\n};\n```
['Depth-First Search', 'Graph', 'C']