[C++] Topological Sort (BFS) + Set Data Structure
\nclass Solution {\nprivate:\n    void makeGraph(vector<int> adj[],vector<vector<int>>& edges,vector<int>& in){\n        for(auto v : edges){\n            adj[v
```\nclass Solution {\nprivate:\n    void makeGraph(vector<int> adj[],vector<vector<int>>& edges,vector<int>& in){\n        for(auto v : edges){\n            adj[v[0]].push_back(v[1]);\n            in[v[1]]++;\n        }\n    }\npublic:\n    vector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        vector<int> adj[n];\n        vector<int> in(n,0);\n        makeGraph(adj,edges,in);\n        vector<set<int>> temp(n);\n        queue<int> q;\n        \n        for(int i=0; i<in.size(); i++){\n            if(in[i] == 0) q.push(i);\n        }\n        while(!q.empty()){\n            int u = q.front();\n            q.pop();\n            for(int v : adj[u]){\n                temp[v].insert(u);\n                temp[v].insert(temp[u].begin(),temp[u].end());\n                if(--in[v] == 0) q.push(v);\n            }\n        }\n        vector<vector<int>> ans(n);\n        for(int i=0; i<n; i++){\n            ans[i].assign(temp[i].begin(),temp[i].end());\n        }\n        return ans;\n    }\n};\n```
['Breadth-First Search', 'Topological Sort', 'C', 'Ordered Set', 'C++']