All Ancestors of a Node in DAG - [C++]  BFS | Topological sorting : Simple clean code
\nvector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        int m = edges.size();\n        \n        vector<int> adj[n];\n        \n       
```\nvector<vector<int>> getAncestors(int n, vector<vector<int>>& edges) {\n        int m = edges.size();\n        \n        vector<int> adj[n];\n        \n        for(int i=0; i<m; i++)\n        {\n            adj[edges[i][0]].push_back(edges[i][1]);\n        }\n        \n        vector<int> indegree(n);\n        \n        for(int i=0; i<n; i++)\n        {\n            for(auto u : adj[i])\n            {\n                indegree[u]++;\n            }\n        }\n        \n        queue<int> q;\n        \n        for(int i=0; i<n; i++)\n        {\n            if(indegree[i] == 0)\n            {\n                q.push(i);\n            }\n        }\n        \n        vector<unordered_set<int>> ump(n);\n        \n        while(!q.empty())\n        {\n            int  i = q.front();\n            \n            for(auto u : adj[i])\n            {\n                ump[u].insert(i);\n                \n                for(auto v : ump[i])\n                {\n                    ump[u].insert(v);\n                }\n                \n                \n                \n                indegree[u]--;\n                \n                if(indegree[u] == 0)\n                {\n                    q.push(u);\n                }\n            }\n            \n            q.pop();\n        }\n        \n        vector<vector<int>> res;\n        \n        for(int i=0; i<n; i++)\n        {\n            vector<int> temp;\n            \n            for(auto v : ump[i])\n            {\n                temp.push_back(v);\n            }\n            \n            sort(temp.begin(), temp.end());\n            \n            res.push_back(temp);\n        }\n        \n        \n        return res;\n    }\n```
['Breadth-First Search', 'Graph', 'Topological Sort', 'C', 'Ordered Set']