dfs from child to parent
approach:\njust take transpose of the graph and call dfs for each node.\nAs graph edges are reversed and we are calling dfs, its like calling dfs from leaf to p
# approach:\njust take transpose of the graph and call dfs for each node.\nAs graph edges are reversed and we are calling dfs, its like calling dfs from leaf to parent, and just keep appending the vertices which are not in ans[node]..... \n\n\n# Code\n```\nclass Solution:\n    def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:\n\n        ans = [[] for _ in range(n)]\n\n        g = defaultdict(list)\n\n        for u, v in edges:\n            g[v].append(u)\n        \n        def dfs(node, curr):\n            for v in g[curr]:\n                if v not in ans[node]:\n                    dfs(node, v)\n                    ans[node].append(v)  \n        \n        for i in range(n):\n            dfs(i,i)\n\n        for k in ans:\n            k.sort()\n            \n        return ans \n\n```
['Python3']