Python3, Simple, 6 lines
Intuition\nWe need to know parent for each node. We are storing it in the array parents.\nProblem is to identify, who is parent and who is a child. When I solve
# Intuition\nWe need to know parent for each node. We are storing it in the array `parents`.\nProblem is to identify, who is parent and who is a child. When I solved this first time, it was true that `parent<child`. Leetcode added later a special test case, where this is not true.\n\nI had to update code. When we are processing an edge, we have to chceck if the child already have a parent. If it is a case, we have to switch parent and child.\n\n**Each child can have only one parent because this is a tree.**\n\nThe problematic edges are `0-2,0-3,1-2`. It looks like node 2 has two parents: 0 and 1, but it is not true. \n0 has two children: 2 and 3\n2 has one child: 1.\n\nOther words: \n0 is a root\nparent of 1 is 2\nparent of 2 is 0\nparent of 3 is 0\n\n```\n      0\n    /   \\\n   2     3\n  /\n 1 \n```\n\n# Complexity\n- Time complexity:\nO(N)\nIt shows better time than 100% Python solutions.\n\n- Space complexity:\nO(N)\nIt shows better space than 97% Python solutions.\n\n# Code\n```\nclass Solution:\n    def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int:\n        parents=[-1]*n\n        for edge in edges:\n            parent,child=edge\n            if parents[child]==-1:\n                parents[child]=parent  \n            else:\n                parents[parent]=child   \n        for h in range(n-1,0,-1):\n            if hasApple[h] and parents[h]!=-1:\n                hasApple[parents[h]]=True\n        return sum(hasApple[1:])*2\n```\n# Short Code - only 6 lines\nThis is just for fun, I prefer the readable version of code.\n```\nclass Solution:\n    def minTime(self, n: int, edges: List[List[int]], hasApple: List[bool]) -> int:\n        parents=[-1]*n\n        for edge in edges:\n            parents[edge[parents[edge[1]]==-1]]=edge[parents[edge[1]]!=-1]   \n        for h in range(n-1,0,-1):\n            hasApple[parents[h]]=max(hasApple[parents[h]],hasApple[h] and parents[h]!=-1)\n        return sum(hasApple[1:])*2\n```
['Python3']