[C++] Brute Force | DFS with a easy trick
Trick: \n While building the adjacency list built the graph in reverse order. i.e from -> to \u274C but to -> from \u2705\n So now the children\'s become the an
# Trick: \n* While building the adjacency list built the graph in reverse order. i.e `from -> to` \u274C but `to -> from` \u2705\n* So now the children\'s become the ancestors.\n* Now simply do DFS and get all the child nodes of each parent node.\n```\nclass Solution {\npublic:\n    void dfs(int node, vector<vector<int>> &adj, vector<int> &curr, vector<bool> &vis)\n    {\n        vis[node] = true;\n        \n        for(int nbr : adj[node])\n        {\n            if(!vis[nbr])\n            {\n                curr.push_back(nbr);\n                \n                dfs(nbr, adj, curr, vis);\n            }\n        }\n    }\n    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        vector<vector<int>> adj(n);\n        for(vector<int> &edge: edges)\n        {\n            adj[edge[1]].push_back(edge[0]);\n        }\n        \n        vector<vector<int>> answer(n);\n        \n        for(int i=0; i<n; ++i)\n        {\n            vector<bool> vis(n, false);\n            \n            vector<int> curr;\n            \n            dfs(i, adj, curr, vis);\n            \n            sort(curr.begin(), curr.end());\n            \n            answer[i] = curr;\n        }\n        return answer;\n    }\n};\n```
['Depth-First Search', 'C', 'C++']