C++✅✅| Straight forward solution🔥🔥
Code\n\nclass Solution {\npublic:\n    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        vector<int> adj[n];\n        for(auto it :
# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        vector<int> adj[n];\n        for(auto it : edges){\n            adj[it[0]].push_back(it[1]);\n        }\n        vector<vector<int>> ans(n);\n        function<void(int, int)> dfs = [&](int node, int parent) -> void {\n            for(auto it : adj[node]){\n                if(ans[it].empty() || ans[it].back() != parent){\n                    ans[it].push_back(parent);\n                    dfs(it, parent);\n                }\n            }\n        };\n        for(int i = 0; i < n; i++){\n            dfs(i, i);\n        }\n        return ans;\n    }\n};\n```
['Depth-First Search', 'C++']