• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Uriel's Corner

            Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
            posts - 0, comments - 50, trackbacks - 0, articles - 594

            Firstly process the edge list and save as a node dict. Then start from node 0, DFS the whole tree. If current node is not root node and (current node has an apple or children nodes have apples), then the resultant time need to +2 (from parent node to current node and back).


             1 #1443
             2 #Runtime: 541 ms (Beats 100%)
             3 #Memory: 54.5 MB (Beats 61.11%)
             4 
             5 class Solution(object):
             6     def minTime(self, n, edges, hasApple):
             7         """
             8         :type n: int
             9         :type edges: List[List[int]]
            10         :type hasApple: List[bool]
            11         :rtype: int
            12         """
            13         nodes = defaultdict(list)
            14         for x, y in edges:
            15             nodes[x].append(y)
            16             nodes[y].append(x)
            17 
            18         def DFS(r, p):
            19             res = 0
            20             for son in nodes[r]:
            21                 if son != p:
            22                     res += DFS(son, r)
            23             if r and (res or hasApple[r]):
            24                 return res + 2
            25             return res
            26 
            27         return DFS(0, -1)
            精品久久久久久久| 久久精品人妻中文系列| 久久国产精品-国产精品| 狠狠久久亚洲欧美专区| 国产精品成人99久久久久 | 久久久精品人妻一区二区三区蜜桃| 青青久久精品国产免费看 | 亚洲国产精品一区二区三区久久 | 国产免费久久久久久无码| 久久精品国产黑森林| 久久人人爽人人爽人人片av高请| 国产精品99久久99久久久| 久久综合伊人77777麻豆| 久久婷婷五月综合国产尤物app| www亚洲欲色成人久久精品| 国产精品中文久久久久久久| 97久久精品无码一区二区天美| 欧美久久久久久午夜精品| 国产三级久久久精品麻豆三级| 久久国产免费| 欧美亚洲国产精品久久蜜芽| 久久婷婷国产剧情内射白浆| 国产99久久久久久免费看| 久久99国产综合精品免费| 伊人色综合久久天天人手人婷| 国产亚洲精久久久久久无码AV| 性欧美丰满熟妇XXXX性久久久| 青春久久| 久久只有这精品99| 午夜精品久久久久9999高清| 精品多毛少妇人妻AV免费久久| 狠狠色丁香久久婷婷综| 韩国免费A级毛片久久| 亚洲第一极品精品无码久久| 国产成年无码久久久免费| 亚洲伊人久久成综合人影院 | 伊人色综合久久天天| 国产99久久精品一区二区| 国产∨亚洲V天堂无码久久久| 久久水蜜桃亚洲av无码精品麻豆| 久久久无码精品亚洲日韩蜜臀浪潮|