[Python] Beats 100% Short DFS Easy to Read
\n    def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int:\n        tree = defaultdict(list)\n        \n        for i,j in edges:\n  
```\n    def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int:\n        tree = defaultdict(list)\n        \n        for i,j in edges:\n            tree[i].append(j)\n\t\t\ttree[j].append(i)\n        \n        def dfs(node, parent):\n            \n            res = 0\n            \n            for child in tree[node]:\n\t\t\t\tif child != parent:\n\t\t\t\t\tres += dfs(child,node)\n        \n            if hasApple[node] and node != 0:\n                hasApple[parent] = True\n                return res+2\n            return res\n            \n        return dfs(0,0)\n```
['Python', 'Python3']