✅ Easy C++ Solution
Code\n\nclass Solution {\n    void dfs(int x, int curr, vector<vector<int>>& ans, vector<vector<int>>& directChild)\n    {\n        for(int ch : directChild[cur
# Code\n```\nclass Solution {\n    void dfs(int x, int curr, vector<vector<int>>& ans, vector<vector<int>>& directChild)\n    {\n        for(int ch : directChild[curr])\n        {\n            if(ans[ch].empty() || ans[ch].back() != x)\n            {\n                ans[ch].push_back(x);\n                dfs(x, ch, ans, directChild);\n            }\n        }\n    }\n\npublic:\n    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        vector<vector<int>> ans(n), directChild(n);\n        for(auto& e : edges)\n        {\n            directChild[e[0]].push_back(e[1]);\n        }\n        for\n        (int i=0;i<n;i++)\n        {\n            dfs(i, i, ans, directChild);\n        }\n        return ans;\n    }\n};\n```
['C++']