[Python] 15-line simple DFS with a little comments
python\nclass Solution:\n    def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int:\n        tree = [[] for _ in range(n)]\n        for
```python\nclass Solution:\n    def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int:\n        tree = [[] for _ in range(n)]\n        for f, t in edges:\n            tree[f].append(t)\n            tree[t].append(f)\n        \n\t\t# Return a the number of steps to reach all apples and come back\n        # to the current node. Return 0 if no apples found.\n        def dfs(parent, node):\n            steps = 0\n            for c in tree[node]:\n                if c != parent:\n                    steps += dfs(node, c)\n            if (hasApple[node] or steps > 0) and node != 0:\n                steps += 2\n            return steps\n        return dfs(-1, 0)\n```
[]