C++ || Topological Sort
```\nclass Solution {\npublic:\n    vector> getAncestors(int n, vector>& edges) {\n        vector>ans(n);\n        int m=edges.size();\n        vector>adj(n);\n
```\nclass Solution {\npublic:\n    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        vector<set<int>>ans(n);\n        int m=edges.size();\n        vector<vector<int>>adj(n);\n        vector<int>indegree(n,0);\n        for(int i=0; i<m; i++)\n        {\n            adj[edges[i][0]].push_back(edges[i][1]);\n            indegree[edges[i][1]]++;\n        }\n        queue<int>q;\n        for(int i=0; i<n; i++)\n        {\n            if(indegree[i]==0)\n                q.push(i);\n        }\n        \n        while(!q.empty())\n        {\n            auto it=q.front();\n            q.pop();\n            \n            for(auto i:adj[it])\n            {\n                indegree[i]--;\n                \n                set<int>s=ans[it];\n                s.insert(it);\n                \n                for (auto itr = s.begin(); itr != s.end(); itr++)\n                {\n                    ans[i].insert(*itr);\n                }\n                \n                if(indegree[i]==0)\n                {\n                    q.push(i);\n                }\n            }\n        }\n        vector<vector<int>>res;\n        for(int i=0; i<n; i++)\n        {\n            vector<int>v;\n            set<int>s=ans[i];\n            for(auto itr = s.begin(); itr != s.end(); itr++)\n            {\n                v.push_back(*itr);\n            }\n            res.push_back(v);\n        }\n        return res;\n    }\n};
[]