output_description: Print the answer.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_1 A_2 ... A_N
      U_1 V_1
      U_2 V_2
      :
      U_{N - 1} V_{N - 1}
attempt: import sys
  
  readline = sys.stdin.readline
  
  inf = 10**9 + 7
  
  
  def merge(d1a, d2a, d1b, d2b):
      la = len(d1a)
      lb = len(d1b)
      k = la + lb
      res1 = [inf] * k
      res2 = [inf] * k
      for i in range(la):
          for j in range(lb):
              res1[i + j] = min(
                  res1[i + j], d1a[i] + d1b[j], d1a[i] + d2b[j], d2a[i] + d1b[j]
              )
              res2[i + j] = min(res2[i + j], d2a[i] + d2b[j])
  
      for j in range(lb):
          if d1b[j] < 0:
              for i in range(la):
                  res1[i + j + 1] = min(res1[i + j + 1], d1a[i])
                  res2[i + j + 1] = min(res2[i + j + 1], d2a[i])
          if d2b[j] < inf:
              for i in range(la):
                  res1[i + j + 1] = min(res1[i + j + 1], d1a[i])
                  res2[i + j + 1] = min(res2[i + j + 1], d2a[i])
      return res1, res2
  
  
  def parorder(Edge, p):
      N = len(Edge)
      par = [0] * N
      par[p] = -1
      stack = [p]
      order = []
      visited = set([p])
      ast = stack.append
      apo = order.append
      while stack:
          vn = stack.pop()
          apo(vn)
          for vf in Edge[vn]:
              if vf in visited:
                  continue
              visited.add(vf)
              par[vf] = vn
              ast(vf)
      return par, order
  
  
  def getcld(p):
      res = [[] for _ in range(len(p))]
      for i, v in enumerate(p[1:], 1):
          res[v].append(i)
      return res
  
  
  N = int(readline())
  A = list(map(int, readline().split()))
  Edge = [[] for _ in range(N)]
  for _ in range(N - 1):
      a, b = map(int, readline().split())
      a -= 1
      b -= 1
      Edge[a].append(b)
      Edge[b].append(a)
  
  P, L = parorder(Edge, 0)
  # C = getcld(P)
  
  dp1 = [[A[i] if A[i] < 0 else inf] for i in range(N)]
  dp2 = [[A[i] if A[i] > 0 else inf] for i in range(N)]
  
  for l in L[:0:-1]:
      p = P[l]
      dp1[p], dp2[p] = merge(dp1[p], dp2[p], dp1[l], dp2[l])
  
  
  ans = inf
  for i in range(N):
      if dp1[0][i] < 0 or dp2[0][i] < inf:
          ans = i
          break
  print(ans)
  
problem_description: Statement
  
  The server in company A has a structure where N devices numbered 1, 2, ..., N
  are connected with N - 1 cables. The i-th cable connects Device U_i and Device
  V_i. Any two different devices are connected through some number of cables.
  
  Each device v (1 \leq v \leq N) has a non-zero integer A_v, which represents
  the following:
  
    * If A_v < 0, Device v is a computer that consumes an electric power of -A_v.
    * If A_v > 0, Device v is a battery that supplies an electric power of A_v.
  
  You have decided to disconnect some number of cables (possibly zero) to
  disable the server. When some cables are disconnected, the devices will be
  divided into some number of connected components. The server will be disabled
  if all of these connected components satisfy one of the following conditions:
  
    * There is no computer in the connected component. That is, A_v is positive for every device v that belongs to the connected component.
    * There is not enough supply of electric power in the connected component. That is, the sum of A_v over all devices v that belong to the connected component is negative.
  
  At least how many cables do you need to disconnect in order to disable the
  server?
samples: [{"input": "7\n    -2 7 5 6 -8 3 4\n    1 2\n    2 3\n    2 4\n    1 5\n    5 6\n    5 7", "output": "1\n    \n\nWe should disconnect the cable connecting Device 1 and Device 2.\n\n* * *"}, {"input": "4\n    1 2 3 4\n    1 2\n    1 3\n    1 4", "output": "0\n    \n\n* * *"}, {"input": "6\n    10 -1 10 -1 10 -1\n    1 2\n    2 3\n    3 4\n    4 5\n    5 6", "output": "5\n    \n\n* * *"}, {"input": "8\n    -2 3 6 -2 -2 -5 3 2\n    3 4\n    7 6\n    6 2\n    8 2\n    5 3\n    1 8\n    3 7", "output": "3\n    \n\n* * *"}, {"input": "10\n    3 4 9 6 1 5 -1 10 -10 -10\n    7 4\n    5 6\n    8 1\n    9 5\n    7 1\n    10 3\n    2 8\n    4 10\n    9 2", "output": "3"}]