Language: C++

#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int n;
VI a;
VVI e;
vector<bool> visit;
VI dp;
VI result;

void dfs(int now, int point){
    auto itr = lower_bound(dp.begin(), dp.begin()+point, a[now]);
    *itr = a[now];
    //dump(now)
    //dump(point)
    //dump(itr-dp.begin())

    if(itr-dp.begin() >= point){
        point++;
    }
    result[now] = point;

    for(auto next : e[now]){
        if(visit[next]){
            continue;
        }
        visit[next] = true;
        dfs(next,point);
    }

}

void Main()
{
    cin>>n;

    a.resize(n);
    REP(i,n){
        cin>>a[i];
    }

    e.resize(n);
    REP(i,n-1){
        int x,y;cin>>x>>y;
        x--;
        y--;
        e[x].PB(y);
        e[y].PB(x);
    }

    dp.resize(n+10,INF);
    visit.resize(n,false);
    result.resize(n);

    visit[0] = true;
    dfs(0,0);

    REP(i,n){
        cout<<result[i]<<endl;
    }



	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:65:12: error: reference to 'visit' is ambiguous
   65 |         if(visit[next]){
      |            ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:48:14: note:                 'std::vector<bool> visit'
   48 | vector<bool> visit;
      |              ^~~~~
a.cc:68:9: error: reference to 'visit' is ambiguous
   68 |         visit[next] = true;
      |         ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:48:14: note:                 'std::vector<bool> visit'
   48 | vector<bool> visit;
      |              ^~~~~
a.cc: In function 'void Main()':
a.cc:93:5: error: reference to 'visit' is ambiguous
   93 |     visit.resize(n,false);
      |     ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:48:14: note:                 'std::vector<bool> visit'
   48 | vector<bool> visit;
      |              ^~~~~
a.cc:96:5: error: reference to 'visit' is ambiguous
   96 |     visit[0] = true;
      |     ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:48:14: note:                 'std::vector<bool> visit'
   48 | vector<bool> visit;
      |              ^~~~~