[Python 3] Reverse direction and Find all Children
Reverse the direction for each edge and find all children of each node instead.\nUse dynamic programming to save the paths of the previous nodes.\nDo UPVOTE if 
Reverse the direction for each edge and find all children of each node instead.\nUse dynamic programming to save the paths of the previous nodes.\nDo **UPVOTE** if you found it helpful.\n\n```\nclass Solution:\n    def getAncestors(self, n: int, edges: List[List[int]]) -> List[List[int]]:\n        ans = [[] for _ in range(n)]\n        \n        graph = defaultdict(list)\n        for f, t in edges:\n            graph[t].append(f)\n        \n        memo = defaultdict(list)\n        def dfs(src):\n            if src in memo:\n                return memo[src]\n            \n            for nei in graph[src]:\n                memo[src] += [nei]+dfs(nei)\n            \n            memo[src] = list(set(memo[src]))\n            return memo[src]\n        \n        for i in range(n):\n            dfs(i)\n        return [sorted(memo[i]) for i in range(n)]\n```
['Dynamic Programming', 'Depth-First Search', 'Graph', 'Python', 'Python3']