C++|| DFS ||Simple Easy solution
\nclass Solution \n{\npublic:\n\nvector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) \n    {\n        vector<vector<int>> g(n);\n        vector<
```\nclass Solution \n{\npublic:\n\nvector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) \n    {\n        vector<vector<int>> g(n);\n        vector<vector<int>>ans(n);\n        \n        for(auto &i:edges)\n        {\n             g[i[0]].push_back(i[1]);\n        }\n        for(int i=0;i<n;i++){\n            dfs(g,ans,i, i);\n        }\n        return ans;\n    }\n    \n    void dfs(vector<vector<int>> &g,vector<vector<int>> &ans,int src, int anc)\n    {\n        for(auto &it : g[src])\n        {\n            if(ans[it].size()==0 || ans[it].back()!=anc)\n            {\n                ans[it].push_back(anc);\n                dfs(g,ans,it,anc);\n            }\n        }\n    }\n};\n```
['Depth-First Search', 'C']