• <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)
            亚洲а∨天堂久久精品9966| 久久99久久99精品免视看动漫| 狠狠色丁香婷婷久久综合不卡| 精品久久久久香蕉网| 一本大道久久a久久精品综合| 久久精品无码免费不卡| 久久精品国产亚洲AV忘忧草18| 久久精品中文无码资源站| 伊人丁香狠狠色综合久久| 久久狠狠爱亚洲综合影院| 久久99国产精品二区不卡| 久久久久久免费视频| 国产精品久久久久…| 久久久www免费人成精品| 精品综合久久久久久88小说 | 亚洲综合久久夜AV | 国产69精品久久久久9999APGF| 99久久无码一区人妻| 亚洲AV无码1区2区久久| 伊人精品久久久久7777| 一本大道加勒比久久综合| 99久久国产综合精品麻豆| 青青草原综合久久大伊人| 久久精品三级视频| 99久久99久久精品国产| 国产三级久久久精品麻豆三级| 精品久久久无码21p发布| 久久噜噜久久久精品66| 色噜噜狠狠先锋影音久久| AV色综合久久天堂AV色综合在| 午夜久久久久久禁播电影| 久久99热这里只有精品国产| 亚洲欧洲久久久精品| 深夜久久AAAAA级毛片免费看| 国产精品内射久久久久欢欢| 欧美亚洲国产精品久久蜜芽| 久久精品国产99国产精品澳门| 国内精品久久久久久野外| 久久99热国产这有精品| 青青青伊人色综合久久| 精品久久久久久国产牛牛app|