#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const long long INF = LLONG_MAX / 2;

vector<int> a;
vector<vector<int> > edges;

void solve(int curr, int prev, vector<vector<long long> >& ans)
{
    // ans[0] : コンピュータが存在しない
    // ans[1] : 電力供給が不足
    ans.assign(2, vector<long long>(1, a[curr]));
    if(a[curr] < 0)
        ans[0][0] = INF;
    else
        ans[1][0] = INF;

    for(int next : edges[curr]){
        if(prev == next)
            continue;

        vector<vector<long long> > v;
        solve(next, curr, v);

        int n = ans[0].size();
        int m = v[0].size();
        vector<vector<long long> > ans2(2, vector<long long>(n+m, INF));
        for(int i=0; i<n; ++i){
            for(int j=0; j<m; ++j){
                ans2[0][i+j] = min(ans2[0][i+j], ans[0][i] + v[0][j]);
                ans2[1][i+j] = min(ans2[1][i+j], ans[1][i] + v[0][j]);
                ans2[1][i+j] = min(ans2[1][i+j], ans[0][i] + v[1][j]);
                ans2[1][i+j] = min(ans2[1][i+j], ans[1][i] + v[1][j]);
                if(v[0][j] < INF/2 || v[1][j] < 0){
                    ans2[0][i+j+1] = min(ans2[0][i+j+1], ans[0][i]);
                    ans2[1][i+j+1] = min(ans2[1][i+j+1], ans[1][i]);
                }
            }
        }
        ans = move(ans2);
    }
}

int main()
{
    int n;
    cin >> n;
    a.resize(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    edges.assign(n, vector<int>());
    for(int i=0; i<n-1; ++i){
        int u, v;
        cin >> u >> v;
        -- u;
        -- v;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }

    vector<vector<long long> > ans;
    solve(0, -1, ans);
    for(int i=0; ; ++i){
        if(ans[0][i] < INF/2 || ans[1][i] < 0){
            cout << i << endl;
            return 0;
        }
    }
}
