import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


immutable INF = 10L^^18;

int N;
long[] A;
int[] U, V;

int[][] G;
int[] sz;
long[][][] dp;

void dfs(int u, int p) {
  foreach (v; G[u]) {
    if (v != p) {
      dfs(v, u);
    }
  }
  sz[u] = 1;
  dp[u] = [[INF, INF]];
  chmin(dp[u][0][(A[u] < 0) ? 1 : 0], A[u]);
  foreach (v; G[u]) {
    if (v != p) {
      auto nxt = new long[][](sz[u] + sz[v], 2);
      foreach (x; 0 .. nxt.length) {
        nxt[x][] = INF;
      }
      foreach (x; 0 .. sz[u]) foreach (s; 0 .. 2) {
        if (dp[u][x][s] < INF) {
          foreach (y; 0 .. sz[v]) foreach (t; 0 .. 2) {
            if (dp[v][y][t] < INF) {
              // connect
              {
                chmin(nxt[x + y][s | t], dp[u][x][s] + dp[v][y][t]);
              }
              // cut
              if (t == 0 || dp[v][y][t] < 0) {
                chmin(nxt[x + y + 1][s], dp[u][x][s]);
              }
            }
          }
        }
      }
      sz[u] += sz[v];
      dp[u] = nxt;
    }
  }
}

void main() {
  try {
    for (; ; ) {
      N = readInt();
      A = new long[N];
      foreach (u; 0 .. N) {
        A[u] = readLong();
      }
      U = new int[N - 1];
      V = new int[N - 1];
      foreach (i; 0 .. N - 1) {
        U[i] = readInt() - 1;
        V[i] = readInt() - 1;
      }
      G = new int[][N];
      foreach (i; 0 .. N - 1) {
        G[U[i]] ~= V[i];
        G[V[i]] ~= U[i];
      }
      sz = new int[N];
      dp = new long[][][N];
      dfs(0, -1);
      debug {
        writefln("sz = %s", sz);
        foreach (u; 0 .. N) {
          writefln("dp[%s] = %s", u, dp[u]);
        }
      }
      int ans = N;
      foreach (x; 0 .. N) foreach (s; 0 .. 2) {
        if (dp[0][x][s] < INF) {
          if (s == 0 || dp[0][x][s] < 0) {
            chmin(ans, x);
          }
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
