parameters: (self, n, edges, hasApple)
return_statement: return 2*max(result[0]-1, 0)
docstring: :type n: int
          :type edges: List[List[int]]
          :type hasApple: List[bool]
          :rtype: int
docstring_summary: :type n: int
          :type edges: List[List[int]]
          :type hasApple: List[bool]
          :rtype: int
docstring_tokens: : type n : int : type edges : List [ List [ int ]] : type hasApple : List [ bool ] : rtype : int
function: def minTime(self, n, edges, hasApple):
          """
          :type n: int
          :type edges: List[List[int]]
          :type hasApple: List[bool]
          :rtype: int
          """
          graph = collections.defaultdict(list)
          for u, v in edges:
              graph[u].append(v)
              graph[v].append(u)
          
          result = [0]
          s = [(1, (-1, 0, result))]
          while s:
              step, params = s.pop()
              if step == 1:
                  par, node, ret = params
                  tmp = [int(hasApple[node])]
                  s.append((3, (tmp, ret)))
                  for nei in reversed(graph[node]):
                      if nei == par:
                          continue
                      new_ret = [0]
                      s.append((2, (new_ret, tmp, ret)))
                      s.append((1, (node, nei, new_ret)))
              elif step == 2:
                  new_ret, tmp, ret = params
                  ret[0] += new_ret[0]
                  tmp[0] |= bool(new_ret[0])
              else:
                  tmp, ret = params
                  ret[0] += tmp[0]
          return 2*max(result[0]-1, 0)
function_tokens: def minTime ( self , n , edges , hasApple ) : graph = collections . defaultdict ( list ) for u , v in edges : graph [ u ] . append ( v ) graph [ v ] . append ( u ) result = [ 0 ] s = [ ( 1 , ( - 1 , 0 , result ) ) ] while s : step , params = s . pop ( ) if step == 1 : par , node , ret = params tmp = [ int ( hasApple [ node ] ) ] s . append ( ( 3 , ( tmp , ret ) ) ) for nei in reversed ( graph [ node ] ) : if nei == par : continue new_ret = [ 0 ] s . append ( ( 2 , ( new_ret , tmp , ret ) ) ) s . append ( ( 1 , ( node , nei , new_ret ) ) ) elif step == 2 : new_ret , tmp , ret = params ret [ 0 ] += new_ret [ 0 ] tmp [ 0 ] |= bool ( new_ret [ 0 ] ) else : tmp , ret = params ret [ 0 ] += tmp [ 0 ] return 2 * max ( result [ 0 ] - 1 , 0 )