Topological sort solution
\nclass Solution:\n    def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:\n        dNodes=defaultdict(set)\n        dIncomming=defaultdi
```\nclass Solution:\n    def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:\n        dNodes=defaultdict(set)\n        dIncomming=defaultdict(int)\n        for a,b in edges:\n            dNodes[a].add(b)\n            dIncomming[b]+=1\n        res=[set() for i in range(n)]\n        q=deque([])\n        for i in range(n):\n            if(dIncomming[i]==0):q.append(i)\n        while(q):\n            p=q.popleft()\n            for j in dNodes[p]:\n                res[j]=res[j].union(res[p])\n                res[j].add(p)\n                dIncomming[j]-=1\n                if(dIncomming[j]==0):q.append(j)\n        for i in range(len(res)):res[i]=sorted(list(res[i]))\n        return res   \n```
['Topological Sort', 'Python3']