// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



#define int long long



const int N=2e5+5;

int a[N];

vector<int> g[N];

int n;

int ans[N];

vector<int> d;

void dfs(int k,int par)

{

    ans[k]=d.size();

    for(auto &it:g[k])

    {

        int temp;

        if(it==par)

            continue;

        bool flag=1;    

        auto itr=lower_bound(d.begin(),d.end(),a[it]);

        int idx=itr-d.begin();

        if(itr==d.end())

            d.push_back(a[it]);

        else

        {

            flag=0;

            temp=*itr;

            *itr=a[it];

        }

        dfs(it,k);

        if(flag)

            d.pop_back();

        else

            d[idx]=temp;

    }

}



void solve(int tt)

{

    cin>>n;

    for(int i=1;i<=n;i++)

        cin>>a[i];

    for(int i=1;i<n;i++)

    {

        int u,v;

        cin>>u>>v;

        g[u].push_back(v);

        g[v].push_back(u);

    }

    d.push_back(a[1]);

    dfs(1,0);

    for(int i=1;i<=n;i++)

        cout<<ans[i]<<endl;

}



int32_t main()

{

    int t=1;

    //cin>>t;

    for(int i=1;i<=t;i++)

        solve(i);

}

// Faster C++ solution for the same problem (measured speedup: 6.3037838852817085x):
#include <bits/stdc++.h>

using namespace std;



typedef long long int ll;

typedef vector<int> vi;			typedef vector<ll> vl;

typedef vector<vi> vvi; 		typedef vector<vl> vvl;

typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;

typedef vector<pii> vii; 		typedef vector<pll> vll;

typedef map<int,int> mii;

typedef vector<char> vc;

typedef vector<bool> vb;

#define endl '\n'

#define forn(i,n) for(int i=0;i<n;i++)

#define rforn(i,n) for(int i=n-1;i>=0;i--)

#define forne(i,n) for(int i=1;i<=n;i++)

#define rforne(i,n) for(int i=n;i>=1;i--)

#define forse(i,s,e) for(int i=s;i<e;i++)

#define rforse(i,s,e) for(int i=e-1;i>=s;i--)

#define all(x) x.begin(),x.end()

#define sz(x) (ll)x.size()

#define MOD 1000000007

#define F first

#define S second

#define pb push_back

#define in insert

#define mp(a, b) make_pair(a, b)

#define fill(a,x) memset(a,x,sizeof a);

#define trav(a,x) for(auto &a:x)

#define min3(a, b, c) min(min(a, b), c)

#define min4(a, b, c, d) min(min(a, b), min(c, d))

#define max3(a, b, c) max(max(a, b), c)

#define max4(a, b, c, d) max(max(a, b), max(c, d))

#define INF LLONG_MAX

#ifdef KARAN

	#include "../../trace.h"

#else

    #define trace(args...)

#endif



ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 

	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}

ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}

ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}

void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}



void dfs(ll v, ll p, ll l, vvl &adj, vl &a, vl &dp, vl &ans){



	ll lo = lower_bound(dp.begin(), dp.end() + l, a[v]) - dp.begin();

	

	ll prev_val = dp[lo];

	dp[lo] = a[v];

	ans[v] = lower_bound(dp.begin(), dp.end() + l, INF) - dp.begin();

	

	for(auto u: adj[v]){

		if(u!=p)

			dfs(u, v, max(lo, l), adj, a, dp, ans);

	}

	dp[lo] = prev_val;

}



void solve(){

	ll n;

	cin>>n;

	vl a(n);

	forn(i, n) cin>>a[i];

	vvl adj(n);

	forn(i, n-1){ ll u, v; cin>>u>>v; u--; v--; adj[u].pb(v); adj[v].pb(u); }

	vl ans(n);

	vl dp(n);

	forn(i, n) dp[i] = INF;

	dfs(0, 0, 0, adj, a, dp, ans);

	for(auto elem: ans)

		cout<<elem<<endl;	

}



int main(){

	ios_base::sync_with_stdio(false);

	cin.tie(NULL);

	cout.tie(NULL);

	#ifdef KARAN

		freopen("inp.txt", "r", stdin);

    	freopen("out.txt", "w", stdout);

    	freopen("err.txt", "w", stderr);

	#endif

	int t=1;

	// cin>>t;

	while(t--)

		solve();

}