Clean Python 3, DFS
Build N-ary tree and perform DFS on it.\nTime: O(N)\nSpace: O(N)\n\nimport collections\nclass TreeNode(object):\n    def __init__(self, val):\n        self.val 
Build N-ary tree and perform DFS on it.\nTime: `O(N)`\nSpace: `O(N)`\n```\nimport collections\nclass TreeNode(object):\n    def __init__(self, val):\n        self.val = val\n        self.children = []\n\nclass Solution:\n    def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int:\n        def dfs(node: TreeNode) -> int:\n            if not node: return 0\n            result = sum((dfs(child) for child in node.children), 0)\n            return result + 1 if hasApple[node.val] or result > 0 else 0\n\n        nodes = {i: TreeNode(i) for i in range(n)}\n        for u, v in edges:\n            nodes[u].children.append(nodes[v])\n        return 2 * sum(dfs(child) for child in nodes[0].children)\n```
[]