Language: C++

/***************************************** START OF TEMPLATE *********************************************/

using namespace std;

#define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  f              first
#define  s              second
#define  pb             push_back
#define  INPa(a,n)      foo(i,1,n) cin>>a[i];
#define  deb2d(a,n,m)   foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}
#define  deb1d(a,n)     foo(i,1,n)cout<<a[i]<<" ";newl;
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<" ";newl;
#define  deb2(a,b)      cout<<a<<" "<<b<<" ";newl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<" ";newl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d;newl;
#define  ll             long long
#define  ld             long double
#define  pll            pair<ll,ll>
#define  vll            vector<ll>
#define  vpll           vector<pll>

const ll   MOD   =  1e+9 + 7;
const ll   INF   =  LLONG_MAX;
const int  INFi  =  INT_MAX;
const ll   N     =  2e+5 + 8;

vll adj[N]; ll vis[N];
ll dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};

ll test_cases = 1; randomINIT;

/*********************************************************************************************************/
/***************************************** VARIABLE DECLARATIONS *****************************************/
ll n, u, v, a[N], dp[N];
map<ll, ll> ID;
/***************************************** FUNCTION IMPLEMENTATIONS **************************************/
ll seg[4 * N + 8];

ll left(ll nd) {return nd << 1;}
ll right(ll nd) {return (nd << 1) + 1;}
ll combine(ll a, ll b) {return max(a, b);}

void update(ll node, ll st, ll en, ll pos, ll val) {
    if (st == en) {
        seg[node] = val;
        return;
    }
    ll mid = (st + en) / 2;
    if (pos <= mid) update(left(node), st, mid, pos, val);
    else update(right(node), mid + 1, en, pos, val);
    seg[node] = combine(seg[left(node)], seg[right(node)]);
}

ll query(ll node, ll st, ll en, ll l, ll r) {
    if (l <= st && en <= r) return seg[node];
    if (st > r || en < l) return 0;

    ll mid = (st + en) / 2;
    ll lq = query(left(node), st, mid, l, r);
    ll rq = query(right(node), mid + 1, en, l, r);

    return combine(lq, rq);
}


void dfs(ll v, ll p) {
    vis[v] = 1;
    dp[v] = max(dp[p], query(1, 1, N, 1, ID[a[v]] - 1) + 1);
    update(1, 1, N, ID[a[v]], dp[v]);

    for (auto to : adj[v]) {
        if (vis[to] == 0) {
            dfs(to, v);
        }
    }

    update(1, 1, N, ID[a[v]], 0);
    vis[v] = 0;
}

void path_compress() {
    set<ll> order;
    ll cnt = 1;
    foo(i, 1, n) order.insert(a[i]);
    for (auto it : order) ID[it] = cnt++;
}
/***************************************** START OF MAIN FUNCTION ****************************************/
void MAIN(ll tc) {
    cin >> n;
    INPa(a, n);
    foo(i, 1, n - 1) {
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    path_compress();
    dfs(1, 1);
    foo(i, 1, n)cout << dp[i] << "\n";
}

int main() {
    SPEED;

    //cin>>test_cases;
    foo(i, 1, test_cases) {
        MAIN(i);
    }
}

Compiler output:
a.cc:31:21: error: 'LLONG_MAX' was not declared in this scope
   31 | const ll   INF   =  LLONG_MAX;
      |                     ^~~~~~~~~
a.cc:1:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
  +++ |+#include <climits>
    1 | /***************************************** START OF TEMPLATE *********************************************/
a.cc:32:21: error: 'INT_MAX' was not declared in this scope
   32 | const int  INFi  =  INT_MAX;
      |                     ^~~~~~~
a.cc:32:21: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc:27:25: error: 'vector' does not name a type
   27 | #define  vll            vector<ll>
      |                         ^~~~~~
a.cc:35:1: note: in expansion of macro 'vll'
   35 | vll adj[N]; ll vis[N];
      | ^~~
a.cc:6:25: error: 'mt19937' does not name a type
    6 | #define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
      |                         ^~~~~~~
a.cc:38:20: note: in expansion of macro 'randomINIT'
   38 | ll test_cases = 1; randomINIT;
      |                    ^~~~~~~~~~
a.cc:43:1: error: 'map' does not name a type
   43 | map<ll, ll> ID;
      | ^~~
a.cc: In function 'long long int combine(long long int, long long int)':
a.cc:49:32: error: 'max' was not declared in this scope
   49 | ll combine(ll a, ll b) {return max(a, b);}
      |                                ^~~
a.cc: In function 'void dfs(long long int, long long int)':
a.cc:76:42: error: 'ID' was not declared in this scope
   76 |     dp[v] = max(dp[p], query(1, 1, N, 1, ID[a[v]] - 1) + 1);
      |                                          ^~
a.cc:76:13: error: 'max' was not declared in this scope
   76 |     dp[v] = max(dp[p], query(1, 1, N, 1, ID[a[v]] - 1) + 1);
      |             ^~~
a.cc:79:20: error: 'adj' was not declared in this scope
   79 |     for (auto to : adj[v]) {
      |                    ^~~
a.cc: In function 'void path_compress()':
a.cc:90:5: error: 'set' was not declared in this scope
   90 |     set<ll> order;
      |     ^~~
a.cc:1:1: note: 'std::set' is defined in header '<set>'; this is probably fixable by adding '#include <set>'
  +++ |+#include <set>
    1 | /***************************************** START OF TEMPLATE *********************************************/
a.cc:24:25: error: expected primary-expression before 'long'
   24 | #define  ll             long long
      |                         ^~~~
a.cc:90:9: note: in expansion of macro 'll'
   90 |     set<ll> order;
      |         ^~
a.cc:92:18: error: 'order' was not declared in this scope
   92 |     foo(i, 1, n) order.insert(a[i]);
      |                  ^~~~~
a.cc:93:20: error: 'order' was not declared in this scope
   93 |     for (auto it : order) ID[it] = cnt++;
      |                    ^~~~~
a.cc:93:27: error: 'ID' was not declared in this scope
   93 |     for (auto it : order) ID[it] = cnt++;
      |                           ^~
a.cc: In function 'void MAIN(long long int)':
a.cc:97:5: error: 'cin' was not declared in this scope
   97 |     cin >> n;
      |     ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | /***************************************** START OF TEMPLATE *********************************************/
a.cc:101:9: error: 'adj' was not declared in this scope
  101 |         adj[u].pb(v);
      |         ^~~
a.cc:106:17: error: 'cout' was not declared in this scope
  106 |     foo(i, 1, n)cout << dp[i] << "\n";
      |                 ^~~~
a.cc:106:17: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc: In function 'int main()':
a.cc:5:25: error: 'ios' has not been declared
    5 | #define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
      |                         ^~~
a.cc:110:5: note: in expansion of macro 'SPEED'
  110 |     SPEED;
      |     ^~~~~
a.cc:5:50: error: 'cin' was not declared in this scope
    5 | #define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
      |                                                  ^~~
a.cc:110:5: note: in expansion of macro 'SPEED'
  110 |     SPEED;
      |     ^~~~~
a.cc:5:50: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    5 | #define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
      |                                                  ^~~
a.cc:110:5: note: in expansion of macro 'SPEED'
  110 |     SPEED;
      |     ^~~~~
a.cc:5:61: error: 'cout' was not declared in this scope
    5 | #define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
      |                                                             ^~~~
a.cc:110:5: note: in expansion of macro 'SPEED'
  110 |     SPEED;
      |     ^~~~~
a.cc:5:61: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    5 | #define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
      |                                                             ^~~~
a.cc:110:5: note: in expansion of macro 'SPEED'
  110 |     SPEED;
      |     ^~~~~
a.cc:5:79: error: 'fixed' was not declared in this scope
    5 | #define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
      |                                                                               ^~~~~
a.cc:110:5: note: in expansion of macro 'SPEED'
  110 |     SPEED;
      |     ^~~~~
a.cc:1:1: note: 'std::fixed' is defined in header '<ios>'; this is probably fixable by adding '#include <ios>'
  +++ |+#include <ios>
    1 | /***************************************** START OF TEMPLATE *********************************************/
a.cc:5:91: error: 'setprecision' was not declared in this scope
    5 | #define  SPEED          ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
      |                                                                                           ^~~~~~~~~~~~
a.cc:110:5: note: in expansion of macro 'SPEED'
  110 |     SPEED;
      |     ^~~~~
a.cc:1:1: note: 'std::setprecision' is defined in header '<iomanip>'; this is probably fixable by adding '#include <iomanip>'
  +++ |+#include <iomanip>
    1 | /***************************************** START OF TEMPLATE *********************************************/