较小权值到较大权值连一条边,找每个点能够到达的最多的点数,取最大值
#pragma comment(linker, "/STACK:102400000,102400000")
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1 | 1
#define lowbit(x) x&(-x)
using namespace std;
const int N=5e5+10;
long long INF=-1e15;
int T,n,m,k;
int ans;
const int MOD=1e9+7;
int tot;
struct node{
int v,id;
}vec[N];
bool operator<(const node&x,const node & y){
return x.v<y.v;
}
int w[N],r[N];
vector<int> G[N];
int main()
{
#ifndef ONLINE_JUDGE
freopen("aaa","r",stdin);
#endif
int T;
while(~scanf("%d",&n)){
for(int i=1;i<=n;i++) G[i].clear();
for(int i=1;i<=n;i++){
scanf("%d",&w[i]);
vec[i].id=i;
vec[i].v=w[i];
}
for(int i=0;i<n-1;i++){
int u,v;
scanf("%d%d",&u,&v);
G[u].push_back(v);
G[v].push_back(u);
}
sort(vec+1,vec+n+1);
ans=1;
for(int i=n;i;i--){
int id=vec[i].id;
r[id]=1;
for(int j=0;j<G[id].size();j++){
int u=G[id][j];
if(w[id]>w[u]) continue;
r[id]+=r[u];
}
ans=max(ans,r[id]);
}
printf("%d\n",ans);
}
return 0;
}