• <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)
            久久久青草久久久青草| 久久青青草原精品国产| 久久久久久国产精品免费免费| 久久精品国产亚洲av瑜伽| 国产精品久久久久久久人人看 | 人人狠狠综合久久88成人| 99久久无色码中文字幕| 色综合久久88色综合天天 | 无码人妻少妇久久中文字幕蜜桃| 99久久www免费人成精品| 伊人久久久AV老熟妇色| 久久本道久久综合伊人| 久久国产精品一区二区| 亚洲午夜久久久久久久久电影网| 久久久久亚洲精品无码网址| 99久久精品国内| 77777亚洲午夜久久多人| 久久人人爽人爽人人爽av| 久久天堂电影网| 无码专区久久综合久中文字幕| 久久久人妻精品无码一区| 久久精品国产亚洲欧美| 99久久777色| 99久久免费国产精品热| 欧美牲交A欧牲交aⅴ久久| 三级三级久久三级久久| 免费精品国产日韩热久久| 久久强奷乱码老熟女| 久久精品亚洲欧美日韩久久| 伊人久久大香线焦综合四虎| 久久精品国产99国产精品澳门 | 亚洲熟妇无码另类久久久| 思思久久好好热精品国产| 青青青青久久精品国产h久久精品五福影院1421| 99久久精品国产麻豆| 久久综合丝袜日本网| 国产精品免费久久| 欧美国产精品久久高清| 久久亚洲AV无码精品色午夜| 亚洲色婷婷综合久久| 国产精品免费福利久久|