Simple C++ Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- O(NN)
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- O(N*N)\n\n- Space complexity:\n- O(N*N)\n\n# Code\n```\nclass Solution {\npublic:\n    map<int,vector<int>>mp;\n    void fill(vector<vector<int>>& edges){\n        for(auto i:edges){\n            int u=i[0],v=i[1];\n            mp[v].push_back(u);\n        }\n        return;\n    }\n    void dfs(int node,vector<bool>&vis,set<int>&ans){\n        int kk=node;\n        if(mp.find(node)==mp.end()){\n            ans.insert(node);\n            return;\n        }\n        vis[node]=true;\n        ans.insert(node);\n\n        for(auto i:mp[node]){\n            if(!vis[i]) dfs(i,vis,ans);\n        }\n        return;\n    }\n    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        mp.clear();\n        fill(edges);\n        \n        vector<vector<int>>ans;\n\n        for(int i=0;i<n;i++){\n            if(mp.find(i)==mp.end()){\n                ans.push_back({});\n                continue;\n            }\n            vector<bool>vis(n+1,false);\n            set<int>res;\n\n            dfs(i,vis,res);\n\n            if(res.find(i)!=res.end()) res.erase(i);\n\n            vector<int>temp(res.begin(),res.end());\n            \n            ans.push_back(temp);\n        }\n        return ans;\n    }\n};\n```
['Depth-First Search', 'Breadth-First Search', 'Graph', 'Topological Sort', 'C++']