• <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)
            久久影视国产亚洲| 久久婷婷五月综合成人D啪| 久久精品国产2020| 久久精品欧美日韩精品| 青青青国产成人久久111网站| 久久午夜综合久久| 精品免费久久久久久久| 国产AV影片久久久久久| 无码伊人66久久大杳蕉网站谷歌| 人人狠狠综合久久亚洲88| 久久婷婷五月综合色高清| 久久国产免费直播| 99久久这里只有精品| 99久久香蕉国产线看观香| 久久狠狠高潮亚洲精品| 久久天天躁夜夜躁狠狠躁2022| 久久综合九色综合久99| 亚洲AV无码1区2区久久| 亚洲国产香蕉人人爽成AV片久久 | 精品一久久香蕉国产线看播放| 2021最新久久久视精品爱| 国产精品嫩草影院久久| 久久97精品久久久久久久不卡| 区久久AAA片69亚洲| 久久久免费观成人影院| 久久香蕉国产线看观看99| 久久99精品国产麻豆| 久久精品国产亚洲av水果派| 国产精品久久久久久久人人看| 亚洲国产成人久久一区WWW| 久久九九免费高清视频| 国产精品美女久久久久av爽| 99久久精品九九亚洲精品| 久久亚洲精品中文字幕三区| 久久久久久久97| 久久一日本道色综合久久| 久久香综合精品久久伊人| 潮喷大喷水系列无码久久精品| 色狠狠久久AV五月综合| 97久久久精品综合88久久| 久久99国产精品一区二区|