文件目录

// 有向图 记忆化搜索
#include <bits/stdc++.h>
using namespace std;
vector<int> e[100005]; // 邻接表
int vis[100005] = {};
int dfs(int x)
{
    if (vis[x])
        return vis[x];
    int sum = 0;
    for (int i = 0; i < e[x].size(); i++)
    {
        sum += dfs(e[x][i]);
    }
    return vis[x] = sum + 1;
}
int main()
{
    int n;
    cin >> n;
    int a[100005] = {};
    for (int i = 1; i <= n; i++)
        scanf("%d", a + i);
    for (int i = 1, u, v; i < n; i++)
    {
        scanf("%d %d", &u, &v);
        if (a[u] < a[v])
            e[v].push_back(u);
        else if (a[v] < a[u])
            e[u].push_back(v);
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        ans = max(dfs(i), ans);
    cout << ans;
    return 0;
}