Reverse all edges and DFS from every node
\nclass Solution:\n    def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:\n        graph = {}\n        for a, b in edges:\n            g
```\nclass Solution:\n    def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:\n        graph = {}\n        for a, b in edges:\n            graph[b] = graph.get(b, []) + [a]\n        op = [[] for i in range(n)]\n        for a in graph:\n            visited = set()\n            paths = [a]\n            while len(paths) > 0:\n                curr = paths.pop()\n                for b in graph.get(curr, []):\n                    if b not in visited:\n                        visited.add(b)\n                        paths.append(b)\n            op[a] = sorted(visited)\n        return op\n```
['Python']