criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+2;

//compress A[i] first
//so that we can use LIS via Segment tree

long long s;
long long e;
long long val;
long long segtree[N << 2];

void update(int P , int L , int R){
     if(L > e || R < s){
        return;
     } else if(s <= L && R <= e) {
        segtree[P] = val;
        return;
     }
     int mid = (L + R) >> 1;
     update( (P << 1) | 0 , L , mid + 0);
     update( (P << 1) | 1 , mid + 1 , R);
     //segtree[P] = segtree[P << 1] + segtree[P << 1 | 1];
     segtree[P] = max(segtree[P << 1] , segtree[P << 1 | 1]);
}

long long query(int P , int L , int R){
    if(L > e || R < s){
        return 0;
    } else if(s <= L && R <= e){
        return segtree[P];
    } else {
        int mid = (L + R) >> 1;
        long long a = query( (P << 1) | 0 , L , mid + 0);
        long long b = query( (P << 1) | 1 , mid + 1 , R);
        return max(a , b);
    }
}

int n;
int a[N];
int ans[N];
map < int , int > to;
vector < int > adj[N];

void dfs(int u , int p){
    //cout << u << "\n";
    s = 1 , e = a[u] - 1;

    ans[u] = query(1 , 1 , n) + 1;
    e++;
    s = e;
    val = ans[u];
    update(1 , 1 ,  n);

    ans[u] = max(ans[u] , mx);

    for(auto v : adj[u]){
        if(v == p)
            continue;
        dfs(v , u);
    }

    s = a[u];
    e = a[u];
    val = 0;
    update(1 , 1 , n);
}

int main(){
    scanf("%d" , &n);
    vector < int > all;
    for(int i = 1; i <= n; i++){
        scanf("%d" , &a[i]);
        all.push_back(a[i]);
    }
    int idx = 2;
    sort(all.begin() , all.end());
    for(int i = 0; i < n; i++){
        if(!i){
            to[all[i]] = idx;
            continue;
        }
        if(all[i] == all[i - 1]){
            to[all[i]] = to[all[i - 1]];
        } else {
            to[all[i]] = ++idx;
        }
    }
    for(int i = 1; i <= n; i++){
        a[i] = to[a[i]];
    }

    for(int i = 1; i < n; i++){
        int u , v;
        scanf("%d%d" , &u , &v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1 , 0);
    for(int i = 1; i <= n; i++){
        printf("%d\n" , ans[i]);
    }
}


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:58:27: error: 'mx' was not declared in this scope
   58 |     ans[u] = max(ans[u] , mx);
      |                           ^~
Language: C++

#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cassert>

#define INF 1000000000LL

using namespace std;
using ll = long long int;

#define rep(i, n) for(ll i = 0; i < (n); i++)

ll N;
vector<ll> graph[200001];
vector<ll> A(200001);
vector<ll> L(200001);
vector<ll> dp(200001, INF);

void search(ll v, ll par, ll depth) {
  auto lb = lower_bound(dp.begin(), dp.begin() + depth, A[v]);
  ll old = *lb; // for roll-back
  *lb = A[v];
  L[v] = lower_bound(dp.begin(), dp.begin() + depth, INF) - dp.begin();

  for (ll cld : graph[v]) {
    if (cld == par) continue;
    search(cld, v, depth + 1);
  }

  *lb = old;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  cin >> N;
  rep(i, N) {
    cin >> A[i];
  }
  rep(i, N - 1) {
    ll u, v;
    cin >> u >> v;
    u--; v--;
    graph[u].emplace_back(v);
    graph[v].emplace_back(u);
  }

  search(0, -1, 1);

  rep(i, N) {
    cout << L[i] << endl;
  }

  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:49:9: warning: ignoring return value of '_ForwardIterator std::search(_ForwardIterator, _ForwardIterator, const _Searcher&) [with _ForwardIterator = int; _Searcher = int]', declared with attribute 'nodiscard' [-Wunused-result]
   49 |   search(0, -1, 1);
      |   ~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:4184:5: note: declared here
 4184 |     search(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h: In instantiation of '_ForwardIterator std::search(_ForwardIterator, _ForwardIterator, const _Searcher&) [with _ForwardIterator = int; _Searcher = int]':
a.cc:49:9:   required from here
   49 |   search(0, -1, 1);
      |   ~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:4186:24: error: expression cannot be used as a function
 4186 |     { return __searcher(__first, __last).first; }
      |              ~~~~~~~~~~^~~~~~~~~~~~~~~~~
Language: C++

#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;

void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

constexpr int INF = 1e9+1;
struct Graph {
  vector<vector<int>> edge;
  Graph(int n = 0) { resize(n); }
  void resize(int n) {
    edge.resize(n, vector<int>());
  }
  void addEdge(int from, int to) {
    edge[from].push_back(to); edge[to].push_back(from);
  }
  vector<int>& operator[](int from) { return edge[from]; }
};

vi ans, A;
void dfs(Graph &G, vi &lis, int cur, int prev) {
  auto it = all(lower_bound, lis, A[cur]);
  int before = *it;
  *it = A[cur];
  debug(cur, lis);
  ans[cur] = (int)(all(lower_bound, lis, INF) - lis.begin())-1;
  for (const auto& to:G[cur]) {
    if (to == prev)
      continue;
    dfs(G, lis, to, cur);
  }
  *it = before;
}

int main() {
  int N; cin >> N;

  A.resize(N);
  ans.resize(N, -1);
  Graph G(N);
  rep(i, N) cin >> A[i];
  rep(i, N-1) {
    int u, v; ins(u, v); --u, --v;
    G.addEdge(u, v);
  }
  vi lis(N+1, INF); lis[0] = -INF;
  dfs(G, lis, 0, -1);
  rep(i, N)
    cout << ans[i] << endl;

  return 0;
}


Compiler output:
a.cc: In function 'void dfs(Graph&, vi&, int, int)':
a.cc:30:3: error: 'debug' was not declared in this scope
   30 |   debug(cur, lis);
      |   ^~~~~
Language: C++

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)
const i64 INF = 1LL << 62;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<i64> a(N);
  for (auto& x : a) {
    cin >> x;
  }
  vector<vector<int>> adj(N);
  REP(i, N - 1) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  vector<int> ans(N);
  vector<i64> lis(N + 1, INF);
  auto solve = [&](auto rec, int node, int pnode) -> void {
    auto it = lower_bound(lis.begin(), lis.end(), a[node]);
    assert(it != lis.end());
    int j = distance(lis.begin(), it);
    assert(ans[node] == 0);
    ans[node] = 1 + j;
    i64 bak = lis[j];
    lis[j] = a[node];
    for (auto c : adj[node]) {
      if (c != pnode) {
        rec(rec, c, node);
      }
    }
    lis[j] = bak;
  };
  solve(solve, 0, -1);
  for (auto x : ans) {
    assert(x > 0);
    cout << x << endl;
  }
}


Compiler output:
a.cc: In lambda function:
a.cc:33:5: error: there are no arguments to 'assert' that depend on a template parameter, so a declaration of 'assert' must be available [-fpermissive]
   33 |     assert(it != lis.end());
      |     ^~~~~~
a.cc:33:5: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
a.cc:35:5: error: there are no arguments to 'assert' that depend on a template parameter, so a declaration of 'assert' must be available [-fpermissive]
   35 |     assert(ans[node] == 0);
      |     ^~~~~~
a.cc: In function 'int main()':
a.cc:48:5: error: 'assert' was not declared in this scope
   48 |     assert(x > 0);
      |     ^~~~~~
a.cc:4:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
    3 | #include <vector>
  +++ |+#include <cassert>
    4 | using namespace std;
a.cc: In instantiation of 'main()::<lambda(auto:1, int, int)> [with auto:1 = main()::<lambda(auto:1, int, int)>]':
a.cc:46:8:   required from here
   46 |   solve(solve, 0, -1);
      |   ~~~~~^~~~~~~~~~~~~~
a.cc:33:11: error: 'assert' was not declared in this scope
   33 |     assert(it != lis.end());
      |     ~~~~~~^~~~~~~~~~~~~~~~~
a.cc:33:11: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
a.cc:35:11: error: 'assert' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation
   35 |     assert(ans[node] == 0);
      |     ~~~~~~^~~~~~~~~~~~~~~~
a.cc:33:11: note: 'assert' declared here, later in the translation unit
   33 |     assert(it != lis.end());
      |     ~~~~~~^~~~~~~~~~~~~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	int N, A[200000]; cin >> N;
	REP(i, N) cin >> A[i];

	vector<vint> G(N);
	REP(i, N-1){
		int u, v; cin >> u >> v;
		u--; v--;
		G[u].eb(v); G[v].eb(u);
	}

	vint dp(N+10, 2e9); dp[0] = 0;
	stack<pint> sta;
	vint ans(N, 1);
	vector<bool> visit(N, 0); visit[0] = 1;

	auto dfs = [&](auto &&dfs, int pos) -> void {
		int i = lower_bound(ALL(dp), A[pos]) - dp.begin();
		sta.push({i, dp[i]});
		dp[i] = A[pos];
		ans[pos] = lower_bound(ALL(dp), 2e9);
		for(int nx: G[pos]){
			if(visit[nx]) continue;
			visit[nx] = 1;
			dfs(dfs, nx);
		}
		pint prev = sta.top(); sta.pop();
		dp[prev.first] = prev.second;
	};

	dfs(dfs, 0);

	REP(i, N){
		cout << ans[i] << ln;
	}
}


Compiler output:
a.cc: In lambda function:
a.cc:59:39: error: cannot convert '__gnu_cxx::__normal_iterator<int*, std::vector<int> >' to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} in assignment
   59 |                 ans[pos] = lower_bound(ALL(dp), 2e9);
      |                            ~~~~~~~~~~~^~~~~~~~~~~~~~
      |                                       |
      |                                       __gnu_cxx::__normal_iterator<int*, std::vector<int> >
Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
const int INF = 1001001001;
int n;
std::vector<int> a, ans;
std::vector<std::vector<int>> to; //隣接情報
asing Subsequence

void dfs(int v, int p = -1){
	int i = std::lower_bound(dp.begin(), dp.end(), a[v]) - dp.begin();
	int old = dp[i];
	dp[i] = a[v];
	ans[v] = i;
	if(p != -1){
		ans[v] = std::max(ans[v], ans[p]);
	}
	for(int u : to[v]){
		if(u == p) continue;
		dfs(u, v);
	}
	dp[i] = old;
}

int main(){
	std::cin >>n;
	a = ans = dp = std::vector<int>(n);
	to = std::vector<std::vector<int>>(n);
	for(int i=0; i<n; i++){
		std::cin >> a[i];
	}
	for(int i=0; i<n-1; i++){
		int u, v;
		std::cin >> u >> v;
		u--;
		v--;
		to[u].push_back(v);
		to[v].push_back(u);
	}
	for(int i=0; i<n; i++){
		dp[i] = INF;
	}
	
	dp[0] = -INF;
	dfs(0);
	for(int i=0; i<n; i++){
		std::cout << ans[i] << std::endl;
	}
	
	return 0;
}

Compiler output:
a.cc:8:1: error: 'asing' does not name a type
    8 | asing Subsequence
      | ^~~~~
a.cc: In function 'int main()':
a.cc:27:19: error: 'dp' was not declared in this scope
   27 |         a = ans = dp = std::vector<int>(n);
      |                   ^~
a.cc:45:9: error: 'dfs' was not declared in this scope
   45 |         dfs(0);
      |         ^~~
Language: C++

#include <bits/stdc++.h>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

vi g[100010];
vi a, l;
vi dp;

void dfs(int v, int p=-1){
    int pos = lower_bound(all(dp), a[v]+1) - dp.begin();
    int tmp = dp[pos];
    dp[pos] = a[v];
    l[v] = lower_bound(all(dp), INF) - dp.begin();
    for(auto u : g[v]){
        if(u == p) continue;
        dfs(u, v);
    }
    dp[pos] = tmp;
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    a = vi(n+10;
    l = vi(n+10, 0);
    rep(i,n) cin >> a[i];
    rep(i,n-1){
        int u, v; cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dp = vi(n+10, INF);
    dfs(0);
    rep(i,n) cout << l[i] << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:70:11: error: expected primary-expression before '(' token
   70 |     a = vi(n+10;
      |           ^
a.cc:70:16: error: expected ')' before ';' token
   70 |     a = vi(n+10;
      |           ~    ^
      |                )
Language: C++

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define a first
#define b second
#define pb push_back
int ma=0;
int ss[200001];
int ans[200001];
int it[200001];
vector<int> adj[200001];
void dfs(int no,int par=-1){
	pair<int,pair<int,int>> rev;
	if(ma==0){
		ss[0]=it[no];
		ma+=1;
		rev={-1,{-1,-1}};
	}
	else if(it[no]>ss[ma-1]){
		ma+=1;
		ss[ma-1]=it[no];
		rev={-1,{-1,-1}};
	}
	else if(it[no]==ss[ma-1]){
	}
	else{
		int low=0;
		int high=ma-1;
		while(low<high-1){
			int mid=(low+high)/2;
			if(ss[mid]>it[no]){
				high=mid;
			}
			else{
				low=mid+1;
			}
		}
		int ind=ma-1;
		for(int i=low;i<high+1){
			if(ss[i]>it[no]){
				ind=min(ind,i);
			}
		}
		rev={ind,{ss[ind],it[no]}};
		ss[ind]=it[no];
	}
	ans[no]=ma;
	for(auto j:adj[no]){
		if(j==par){
			continue;
		}
		dfs(j,no);
	}
	if(rev.a!=-1){
		ss[rev.a]=rev.b.a;
	}
	else{
		ma-=1;
	}
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	
	for(int i=0;i<n;i++){
		cin>>it[i];
	}
	int aa,bb;
	for(int i=0;i<n-1;i++){
		cin>>aa>>bb;
		adj[aa-1].pb(bb-1);
		adj[bb-1].pb(aa-1);
	}
	dfs(0,-1);
	for(int i=0;i<n;i++){
		cout<<ans[i]<<endl;
	}

	return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:41:39: error: expected ';' before ')' token
   41 |                 for(int i=low;i<high+1){
      |                                       ^
      |                                       ;
Language: C++

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
ll mod = 1000000007;
int INF = 0x3f3f3f3f;

vector<vector<int> > G;
vector<int> a;
vector<int> a2;
vector<int> res;
vector<bool> used;

class ST {
public:
    vector<int> t;
    int n;

    int combine(int l, int r) {
        return max(l, r);
    }

    ST(int n) {
        this->n = n;
        t = vector<int>(n << 1, 0);
    }


    void update(int i, int value) {
        t[i += n] = value;
        i >>= 1;
        while (i > 0) {
            t[i] = combine(t[i << 1], t[i << 1 | 1]);
            i >>= 1;
        }
    }

    //[l, r)
    int query(int l, int r) {
        int resl = 0, resr = 0;
        for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
            if ((l & 1) != 0) resl = combine(resl, t[l++]);
            if ((r & 1) != 0) resr = combine(t[--r], resr);
        }
        return combine(resl, resr);
    }
};

void dfs(ST& st, int id) {
    int t1 = st.query(0, a2[id]);
    int t2 = st.query(0, a2[id] + 1);
    used[id] = true;
    st.update(a2[id], t1 + 1);
    res[id] = st.query(0, a2[id] + 1);

    for(auto v : G[id]) {
        if(!used[v]) {
            dfs(st, v);
        }
    }

    st.update(a2[id], t2);
}

int main() {
    int n;
    cin >> n;
    a = vector<int>(n + 1);
    res = vector<int>(n + 1);
    a2 = vector<int>(n + 1);
    used = vector<bool>(n + 1 , false);
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    G = vector<vector<int> >(n + 1, vector<int>());
    for(int i = 1; i <= n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    map<int, int> mp;
    for(int i = 1; i <= n; ++i) {
        if(mp.find(a[i]) == mp.end()) {
            mp[a[i]] = 0;
        }
    }
    int id = 0;
    for(auto& v : mp) {
        v.second = id++;
    }

    for(int i = 1; i <= n; ++i) {
        a2[i] = mp[a[i]];
    }

    ST st(mp.size());

    dfs(st, 1, 0);

    for(int i = 1; i <= n; ++i) {
        cout << res[i] << endl;
    }

    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:101:8: error: too many arguments to function 'void dfs(ST&, int)'
  101 |     dfs(st, 1, 0);
      |     ~~~^~~~~~~~~~
a.cc:50:6: note: declared here
   50 | void dfs(ST& st, int id) {
      |      ^~~
Language: C++

#include <iostream>

#include <deque>
#include <queue>
#include <map>

using namespace std;
#define INF 1500000000

 int N,A[200001];

 int parent[200001]={0}; 
 int depth[200001];

int minweight(int vertex,int length);

map<int,int> mem_dp[200001];

int minweight(int vertex,int length){
 if(length<=0)
   return 0;
 if(vertex == 1){
	if(length<=1)
      return A[1];
	else
      return INF;
 }
 if(mem_dp[vertex].find(length)!=mem_dp[vertex].end())
   return mem_dp[vertex][length];
 
  mem_dp[vertex][length] = min(minweight(parent[vertex],length),minweight(parent[vertex],length-1)<A[vertex]?A[vertex]:INF); 
  return mem_dp[vertex][length];
}

int main(){
 deque<int> nbd[200001];
 int score[200001];
 cin >> N;
 
  for(int i=1; i<=N; i++){
  	cin >> A[i];
  }
  for(int i=1; i<=N-1; i++){
    int u,v;
    cin >> u >> v;
    nbd[u].push_back(v);
    nbd[v].push_back(u);
  }
  
  queue<int> q;
  q.push(1);
  depth[1] = 1;
  parent[1] = -1;
  score[1] = 1;
  while(q.empty()==false){
    for(auto x:nbd[q.front()]){
     if(parent[x]==0){
      parent[x] = q.front(); 
      depth[x] = depth[parent[x]]+1;
      int min=1,max=depth[x];
      while(min!=max){
       int t=(min+max+1)/2;
       if(minweight(x,t))==INF)
        max=t-1; 
       else
        min = t;
      }
      score[x] = min;
      q.push(x);
     }
    }
    q.pop();
  }
  
  for(int k =1; k<=N; k++){
   cout << score[k] << endl; 
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:63:26: error: expected primary-expression before '==' token
   63 |        if(minweight(x,t))==INF)
      |                          ^~
Language: C++

#include <iostream>

#include <deque>
#include <queue>
#include <map>

using namespace std;
#define INF 1500000000

 int N,A[200001];

 int parent[200001]={0}; 
 int depth[200001];

int minweight(int vertex,int length);

map<int,int> mem_dp[200001];

int minweight(int vertex,int length){
 if(length<=0)
   return 0;
 if(vertex == 1){
	if(length<=1)
      return A[1];
	else
      return INF;
 }
 if(mem_dp[vertex].find(length)!=mem_dp[vertex].end())
   return mem_dp[vertex][length];
 
  mem_dp[vertex][length] = min(minweight(parent[vertex],length),minweight(parent[vertex],length-1)<A[vertex]?A[vertex]:INF); 
  return mem_dp[vertex][length];
}

int main(){
 deque<int> nbd[200001];
 int score[200001];
 cin >> N;
 
  for(int i=1; i<=N; i++){
  	cin >> A[i];
  }
  for(int i=1; i<=N-1; i++){
    int u,v;
    cin >> u >> v;
    nbd[u].push_back(v);
    nbd[v].push_back(u);
  }
  
  queue<int> q;
  q.push(1);
  depth[1] = 1;
  parent[1] = -1;
  score[1] = 1;
  while(q.empty()==false){
    for(auto x:nbd[q.front()]){
     if(parent[x]==0){
      parent[x] = q.front(); 
      depth[x] = depth[parent[v]]+1;
      int min=1,max=depth[x];
      while(min!=max){
       int t=(min+max+1)/2;
       if(minweight(x,t))==INF)
        max=t-1; 
       else
        min = t;
      }
      score[x] = min;
      q.push(x);
     }
    }
    q.pop();
  }
  
  for(int k =1; k<=N; k++){
   cout << score[k] << endl; 
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:59:31: error: 'v' was not declared in this scope
   59 |       depth[x] = depth[parent[v]]+1;
      |                               ^
a.cc:63:26: error: expected primary-expression before '==' token
   63 |        if(minweight(x,t))==INF)
      |                          ^~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+5;
int n,a[maxn],head[maxn],cnt,dp[maxn],ans[maxn];
struct node{
	int to,next;
}e[maxn<<1]; 
void add(int u,int v){
	e[++cnt].to=v;
	e[cnt].next=head[u];
	head[u]=cnt;
}
void dfs(int son,int fa){
	int pos=lower_bound(dp+1,dp+1+n,a[son])-dp;
	int temp=dp[pos];
	dp[pos]=a[son];
	ans[son]=max(ans[fa],pos);
	for(int i=head[son];i;i=e[i].next){
		if(e[i].to!=fa){
			dfs(a[i].to,son);
		}
	}
	dp[pos]=temp;
}
int main()
{
   scanf("%d",&n);
   for(int i=1;i<=n;i++){
   	  scanf("%d",&a[i]);
   }
   for(int i=1,u,v;i<=n-1;i++)
   {
   	  scanf("%d %d",&u,&v);
   	  add(u,v);add(v,u);
   }
   memset(dp,0x3f,sizeof(dp));
   dfs(1,0);
   for(int i=1;i<=n;i++)
      printf("%d\n",ans[i]);

return 0;
}


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:21:34: error: request for member 'to' in 'a[i]', which is of non-class type 'int'
   21 |                         dfs(a[i].to,son);
      |                                  ^~
Language: C++

#include <iostream>

#include <deque>
#include <queue>

using namespace std;


int main(){
 int N,A[200001];
 deque<int> nbd[200001];
 deque<int> path[200001];
 int score[200001][2];
 cin >> N;
 
  for(int i=1; i<=N; i++){
  	cin >> A[i];
  }
  for(int i=1; i<=N-1; i++){
    int u,v;
    cin >> u >> v;
    nbd[u].push_back(v);
    nbd[v].push_back(u);
  }
  
  path[1].push_back(1);
  queue<int> q;
  q.push(1);
  score[1][1] = 1;
  score[1][0] = 1;
  while(q.empty()==false){
    for(auto x:nbd[q.front()]){
     if(path[x].empty()){
      q.push(x);
      path[x] = path[q.front()];
       
       
      score[x][1] = 1;
      for(auto i:path[x]){
        if(A[i]<A[x])
        	score[x][1] = max(score[x][1],score[i][1]+1);
      }
       
       
      score[x][0] = max(score[x][1],score[*(path[x].end()-1)][0];
      
       
       
      path[x].push_back(x);
     }
    }
    q.pop();
  }
  
  for(int k =1; k<=N; k++){
   cout << score[k][0] << endl; 
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:45:65: error: expected ')' before ';' token
   45 |       score[x][0] = max(score[x][1],score[*(path[x].end()-1)][0];
      |                        ~                                        ^
      |                                                                 )
Language: C++

#include <iostream>

#include <deque>
#include <queue>

using namespace std;


int main(){
 int N,A[200001];
 deque<int> nbd[200001];
 deque<int> path[200001];
 int score[200001][2];
 cin >> N;
 
  for(int i=1; i<=N; i++){
  	cin >> A[i];
  }
  for(int i=1; i<=N-1; i++){
    int u,v;
    cin >> u >> v;
    nbd[u].push_back(v);
    nbd[v].push_back(u);
  }
  
  path[1].push_back(1);
  queue<int> q;
  q.push(1);
  while(q.empty()==false){
    for(auto x:nbd[q.front()]){
     if(path[x].empty()){
      q.push(x);
      path[x] = path[q.front()];
       
      score[x][0] = 1;
      for(auto i:path[x]){
       score[x][0] = max(score[x][0],score[i][1]+(A[i]<A[x]?1:0)) 
      }
       
       
      score[x][0] = 1;
      for(auto i:path[x]){
        if(A[i]<A[x])
        	score[x][1] = max(score[x][1],score[i][1]+1);
      }
       
      path[x] .push_back(q.front());
     }
    }
  }
  
  for(int k =1; k<=N; k++){
   cout << score[k][0] << endl; 
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:37:66: error: expected ';' before '}' token
   37 |        score[x][0] = max(score[x][0],score[i][1]+(A[i]<A[x]?1:0))
      |                                                                  ^
      |                                                                  ;
   38 |       }
      |       ~
Language: C++

#include <iostream>

#include <deque>
#include <queue>

using namespace std;


int main(){
 int N,A[200001];
 deque<int> nbd[200001];
 deque<int> path[200001];
 int score[200001][2];
 cin >> N;
 
  for(int i=1; i<=N; i++){
  	cin >> A[i];
  }
  for(int i=1; i<=N-1; i++){
    int u,v;
    cin >> u >> v;
    nbd[u].push_back(v);
    nbd[v].push_back(u);
  }
  
  path[1].push_back(1);
  queue<int> q;
  q.push(1);
  while(q.empty()==false){
    for(auto x:nbd[q.front()]){
     if(path[x].empty()){
      q.push(*x);
      path[*x] = path[q.front()];
       
      score[*x][0] = 1;
      for(auto i:path[*x]){
       score[*x][0] = max(score[*x][0],score[*i][1]+(A[*i]<A[*x]?1:0)) 
      }
       
       
      score[*x][0] = 1;
      for(auto i:path[*x]){
        if(A[*i]<A[*x])
        	score[*x][1] = max(score[*x][1],score[*i][1]+1);
      }
       
       
       
       
      path[*x] .push_back(q.front());
     }
    }
  }
  
  for(int k =1; k<=N; k++){
   cout << score[k][0] << endl; 
  }
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:32:14: error: invalid type argument of unary '*' (have 'int')
   32 |       q.push(*x);
      |              ^~
a.cc:33:12: error: invalid type argument of unary '*' (have 'int')
   33 |       path[*x] = path[q.front()];
      |            ^~
a.cc:35:13: error: invalid type argument of unary '*' (have 'int')
   35 |       score[*x][0] = 1;
      |             ^~
a.cc:36:23: error: invalid type argument of unary '*' (have 'int')
   36 |       for(auto i:path[*x]){
      |                       ^~
a.cc:37:14: error: invalid type argument of unary '*' (have 'int')
   37 |        score[*x][0] = max(score[*x][0],score[*i][1]+(A[*i]<A[*x]?1:0))
      |              ^~
a.cc:37:33: error: invalid type argument of unary '*' (have 'int')
   37 |        score[*x][0] = max(score[*x][0],score[*i][1]+(A[*i]<A[*x]?1:0))
      |                                 ^~
a.cc:37:62: error: invalid type argument of unary '*' (have 'int')
   37 |        score[*x][0] = max(score[*x][0],score[*i][1]+(A[*i]<A[*x]?1:0))
      |                                                              ^~
a.cc:41:13: error: invalid type argument of unary '*' (have 'int')
   41 |       score[*x][0] = 1;
      |             ^~
a.cc:42:23: error: invalid type argument of unary '*' (have 'int')
   42 |       for(auto i:path[*x]){
      |                       ^~
a.cc:43:20: error: invalid type argument of unary '*' (have 'int')
   43 |         if(A[*i]<A[*x])
      |                    ^~
a.cc:44:23: error: invalid type argument of unary '*' (have 'int')
   44 |                 score[*x][1] = max(score[*x][1],score[*i][1]+1);
      |                       ^~
a.cc:44:42: error: invalid type argument of unary '*' (have 'int')
   44 |                 score[*x][1] = max(score[*x][1],score[*i][1]+1);
      |                                          ^~
a.cc:50:12: error: invalid type argument of unary '*' (have 'int')
   50 |       path[*x] .push_back(q.front());
      |            ^~
Language: C++

#include <bits/stdc++.h>
using namespace std;

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
// #define INF 1000000000000 //10^12:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

int p[200000][200000]={};
int l[200001];
int INF=1000000001;
int ans[20000];
int n;
int a[20000];

void dp(int v){
   int chg_no,org_fig;
   REP(i,n){
      if(p[v][i]){
         p[v][i]=0;
         p[i][v]=0;
         REP(j,n){
            if(l[j]>a[i]){
               chg_no=j;
               org_fig=l[j];
               l[j]=a[i];
               int k=0;
               while(l[k]<INF) k++;
               ans[i]=k;
               dp(i);
               l[chg_no]=org_fig;
               break;
            }
         }
      }
   }
   return;
}

int main(){
   cin>>n;
   REP(i,n)l[i]=INF;
   REP(i,n) cin>>a[i];
   int u,v;
   REP(i,n-1){
      cin>>u>>v;
      p[--u][--v]=1;
      p[v][u]=1;
   }
   l[0]=a[0];
   ans[0]=1;
   dp(0);
   REP(i,n)cout<<ans[i]<<endl;
   return 0;
}

Compiler output:
a.cc:19:11: error: extended character 　 is not valid in an identifier
   19 | #define S second　//pairの二つ目の要素
      |           ^
Language: C++

#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'

using namespace std;

struct DO{
    vector<int> do_arr;
    int len;

    DO(int n){
        int q1 = 1;
        while (q1 < n){
            q1 *= 2;
        }
        len = q1;
        do_arr.assign(2*q1, 0);
    }

    void change(int q, int x){
        do_arr[len+q] = x;
        q = (len+q)/2;
        while (q > 0){
            do_arr[q] = max(do_arr[2*q], do_arr[2*q+1]);
            q /= 2;
        }
    }

    int ans(int l, int r, int l1, int r1, int q){
        if (l >= r1 || l1 >= r || l == r){
            return 0;
        }
        if (l1 <= l && r <= r1){
            return do_arr[q];
        }
        int m = (l+r)/2;
        return max(ans(l, m, l1, r1, 2*q), ans(m, r, l1, r1, 2*q+1));
    }
};

vector<int> a, ans;
vector<vector<int>> s, d;
DO do_arr = *(new DO(1));

void DFS(int vertex, int parent){
    s[a[vertex]].push_back(do_arr.ans(0, do_arr.len, 0, a[vertex], 1)+1);
    do_arr.change(a[vertex], s[a[vertex]].back());
    ans[vertex] = do_arr.do_arr[1];
    for (int q: d[vertex]){
        if (q != parent){
            DFS(q, vertex);
        }
    }
    s[a[vertex]].pop_back();
    do_arr.change(a[vertex], s[a[vertex]].back());
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    a.assign(n, 0), d.assign(n, {}), ans.assign(n, 0), s.assign(n, {0}), a1.assign(n, {});
    do_arr = *(new DO(n));
    vector<p> a1;
    for (int q = 0; q < n; q++){
        cin >> a1[q].first;
        a1[q].second = q;
    }
    sort(a1.begin(), a1.end());
    int q1 = 0;
    a[a1[0].second] = 0;
    for (int q = 1; q < n; q++){
        q1 += (a1[q].first != a1[q-1].first);
        a[a1[q].second] = q1;
    }
    for (int q = 0; q < n-1; q++){
        int x, y;
        cin >> x >> y;
        d[x-1].push_back(y-1);
        d[y-1].push_back(x-1);
    }
    DFS(0, -1);
    for (int q: ans){
        cout << q << endl;
    }
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:65:74: error: 'a1' was not declared in this scope; did you mean 'y1'?
   65 |     a.assign(n, 0), d.assign(n, {}), ans.assign(n, 0), s.assign(n, {0}), a1.assign(n, {});
      |                                                                          ^~
      |                                                                          y1
Language: C++

#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector <ll> tree[200008];
ll arr[200009];
int ans[200009];
vector <ll> dp(200009,LLONG_MAX);
dfs(int cur,int p)
{
    int pos=lower_bound(dp.begin(),dp.end(),arr[cur])-dp.begin();
    ll x=dp[pos];
    dp[pos]=arr[cur];

    for(ll i:tree[cur])
    {
        if(i!=p)
            dfs(i,cur);
    }
    ans[cur]=lower_bound(dp.begin(),dp.end(),LLONG_MAX)-dp.begin();
    dp[pos]=x;


}
int main()
{
    ll i,j,k,l,m,n;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>arr[i];
    for(i=0;i<n-1;i++)
    {
        ll a,b;
        cin>>a>>b;
        a--;
        b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    dfs(0,-1);
    for(i=0;i<n;i++)
        cout<<ans[i]<<endl;


}


Compiler output:
a.cc:8:1: error: ISO C++ forbids declaration of 'dfs' with no type [-fpermissive]
    8 | dfs(int cur,int p)
      | ^~~
a.cc: In function 'int dfs(int, int)':
a.cc:23:1: warning: no return statement in function returning non-void [-Wreturn-type]
   23 | }
      | ^
Language: Java

package codes;

import FastIO.InputReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class FLISOnTree {
    final int MAXN = (int) (2e5) + 10;
    final int INF = (int) (1e9) + 100;
    List<Integer>[] graph;
    int[] dis;
    int[] dp;
    int[] ans;
    int n;
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        n = in.nextInt();
        graph = new ArrayList[n + 1];
        dis = new int[n + 1];
        ans = new int[n + 1];
        dp = new int[MAXN];
        Arrays.fill(dp, INF);
        for (int i = 1; i <= n; i++) dis[i] = in.nextInt();
        for (int i = 0; i <= n; i++) graph[i] = new ArrayList<>();
        for (int i = 1; i < n; i++) graph[in.nextInt()].add(in.nextInt());
        dfs(1, 1, 1);
        for (int i = 1; i <= n; i++) out.println(ans[i]);
    }

    public void dfs(int node, int par, int depth) {
        int idx = lowerbound(1, Math.min(ans[par], depth), dis[node]);
        ans[node] = idx;
        dp[idx] = dis[node];
//        System.out.println("depth=" + depth + " idx=" + idx + " node=" + node + " cost=" + dis[node]);
//        for (int i = 1; i <= n; i++) System.out.print(dp[i] + " ");
//        System.out.println();
        for (int child : graph[node]) {
            dfs(child, node, depth + 1);
        }
        dp[idx] = dis[node];
    }

    public int lowerbound(int low, int high, int find) {
        while (low <= high) {
            int mid = low + (high - low) / 2;
            if (dp[mid] == find) return mid;
            else if (dp[mid] < find) low = mid + 1;
            else high = mid - 1;
        }
        return low;
    }
}


Compiler output:
Main.java:9: error: class FLISOnTree is public, should be declared in a file named FLISOnTree.java
public class FLISOnTree {
       ^
Main.java:3: error: package FastIO does not exist
import FastIO.InputReader;
             ^
Main.java:17: error: cannot find symbol
    public void solve(int testNumber, InputReader in, PrintWriter out) {
                                      ^
  symbol:   class InputReader
  location: class FLISOnTree
Note: Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors
Language: C++

#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5;
int a[N], dp[N], ans[N], n;
vector <int> g[N];

void dfs(int v, int p = 0) {
    int x = lower_bound(dp, dp + n + 1, a[v]) - dp, val = dp[x];
    dp[x] = a[v], ans[v] = lower_bound(dp, dp + n + 1, inf) - dp;
    for (int u : g[v]) if (u != p) dfs(u, v);
    dp[x] = val;
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v), g[v].push_back(u);
    }
   memset(dp, 31, sizeof dp), dfs(1);
    for (int i = 1; i <= n; i++) cout << ans[i] << "\n";

    return 0;
}


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:10:56: error: 'inf' was not declared in this scope; did you mean 'ynf'?
   10 |     dp[x] = a[v], ans[v] = lower_bound(dp, dp + n + 1, inf) - dp;
      |                                                        ^~~
      |                                                        ynf
Language: C++

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;

#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define endl "\n"
#define sz(x) ((ll)((x).size()))
const ll N=2e5+5,inf=1e9;
ll ary[N];
ll ans[N];
vll G[N];
ll n;
ll tree[4*N];
multiset<ll> res;
ll query(ll nd,ll st,ll ed,ll l,ll r)
{
	if(st>r||ed<l||st>ed)return 0;
	if(st>=l && ed<=r)
		return tree[nd];
	ll mid=(st+ed)/2;
	return max(query(2*nd,st,mid,l,r),query(2*nd+1,mid+1,ed,l,r));
}
void update(ll nd,ll st,ll ed,ll id,ll val)
{
	if(st>=id&&ed<=id)
	{
		tree[nd]=val;
	}
	ll mid=(st+ed)/2;
		update(2*nd,st,mid,id,val);
	else
		update(2*nd+1,mid+1,ed,id,val);
	tree[nd]= max(tree[2*nd],tree[2*nd+1]);
}

ll dfs(ll a,ll p)
{
	ll x=query(1,0,n-1,0,ary[a-1]-1);
	ll pre=query(1,0,n-1,ary[a-1],ary[a-1]);
	res.insert(x+1);
	update(1,0,n-1,ary[a-1],x+1);
	ans[a]=*(--res.end());	
	lp(i,0,G[a].size())
	{
		ll x=G[a][i];
		if(x!=p)
			dfs(x,a);
	}
	update(1,0,n-1,ary[a-1],pre);
	res.erase(res.find(x+1));
	return 0;
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin >> n;
	vll v;
	lp(i,0,n)
	{
		cin >> ary[i];
		v.pb(ary[i]);
	}	    
	map<ll,ll> M;
	sort(all(v));
	ll c=0;
	lp(i,0,n)
	{
		if(M.count(v[i])==0)
		{
			M[v[i]]=c++;
		}
	}
	lp(i,0,n)
	{
		ary[i]=M[ary[i]];
	}
	lp(i,0,n-1)
	{
		ll u,v;
		cin >>u >> v;
		G[u].pb(v);
		G[v].pb(u);
	}
	dfs(1,0);
	lp(i,0,n)
	{
		cout<<ans[i+1]<<endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'void update(ll, ll, ll, ll, ll)':
a.cc:45:9: error: 'else' without a previous 'if'
   45 |         else
      |         ^~~~
Language: C

/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int arr[200200];
int segtree[600600];
int cnt[200200];
vector<int> vi[200200];
vector<int> va;
int sana[200200];
void update(int idx, int l, int r, int id, int val)
{
    if(id < l || id > r) return;
    if(l == r && l == id) {
        segtree[idx] = val;
        return;
    }
    int mid = (l+r) / 2;
    update(idx*2, l, mid, id, val);
    update(idx*2+1, mid+1, r, id, val);
    segtree[idx] = max(segtree[idx*2], segtree[idx*2+1]);
}
int query(int idx, int l, int r, int kiri, int kanan)
{
    if(l > kanan || r < kiri) return 0;
    if(l >= kiri && r <= kanan) return segtree[idx];
    int mid = (l+r) / 2;
    int curr = 0;
    curr = max(curr, query(idx*2, l, mid, kiri, kanan));
    curr = max(curr, query(idx*2+1, mid+1, r, kiri, kanan));
    return curr;
}
const int N = 2e5;
void dfs(int now, int prev)
{
    int last = query(1, 1, N, arr[now], arr[now]);
    int curr = query(1, 1, N, 1, arr[now] - 1);
    curr++;
    update(1, 1, N, arr[now], curr);
    sana[now] = curr;
    for(auto x : vi[now])
    {
        if(x == prev) continue;
        dfs(x, now);
    }
    update(1, 1, N, arr[now], last);
}
int main()
{
	int n,i,j,k,x,y,ans,curr,temp,m;
	int tc;
	cin >> n;
	for(i=1;i<=n;i++)
    {
        scanf("%d",&arr[i]);
        va.push_back(arr[i]);
    }
    sort(va.begin(), va.end());
    for(i=1;i<=n;i++)
    {
        arr[i] = lower_bound(va.begin(), va.end(), arr[i]) - va.begin();
        arr[i]++;
        cout << arr[i] << " ";
    }
    cout << endl;
    for(i=1;i<n;i++)
    {
        cin >> x >> y;
        vi[x].push_back(y);
        vi[y].push_back(x);
    }
    dfs(1, 0);
    for(i=1;i<=n;i++) cout << sana[i] << endl;
	return 0;
}


Compiler output:
main.c:5:10: fatal error: bits/stdc++.h: No such file or directory
    5 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.
Language: C++

#include<bits/stdc++.h>
using namespace std;
const int maxm=2e5+5;
vector<int>g[maxm];
int ans[maxm];
int d[maxm],len;
int a[maxm];
void dfs(int x,int fa){
    int pos=-1;
    int temp=0;
    if(a[x]>d[len]){
        d[++len]=a[x];
        f=1;
    }else{
        int l=1,r=len;
        while(l<=r){//二分插入位置
            int mid=(l+r)/2;
            if(a[x]<=d[mid])pos=mid,r=mid-1;
            else l=mid+1;
        }
        temp=d[pos];//记录位置信息
        d[pos]=a[x];
    }
    ans[x]=len;
    for(int v:g[x]){
        if(v==fa)continue;
        dfs(v,x);
    }
    if(pos==-1){
        len--;
    }else{
        d[pos]=temp;
    }
}
signed main(){
    int n;scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<n;i++){
        int a,b;scanf("%d%d",&a,&b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1,-1);
    for(int i=1;i<=n;i++){
        printf("%d\n",ans[i]);
    }
    return 0;
}

/*

*/


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:13:9: error: 'f' was not declared in this scope
   13 |         f=1;
      |         ^
Language: C++

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int n, a[N], dp[N], cnt = 0;
vector <int> g[N], vec, last[N];
map <int, int> mm;

struct SegmentTree {
    int node[N << 2];
    void init (int i, int l, int r) {
        if (l == r) {
            node[i] = 0;
            return;
        }
        
        int mid = l + r >> 1;
        init(i << 1, l, mid);
        init(i << 1 | 1, mid + 1, r);
        node[i] = max(node[i << 1], node[i << 1 | 1]);
    }
    
    void update (int i, int l, int r, int pos, int val) {
        if (l == r) {
            node[i] = max(node[i], val);
            return;
        }
        
        int mid = l + r >> 1;
        if (pos <= mid) update(i << 1, l, mid, pos, val);
        else update(i << 1 | 1, mid + 1, r, pos, val);
        node[i] = max(node[i << 1], node[i << 1 | 1]);
    }
    
    int query (int i, int l, int r, int a, int b) {
        if (l > r || a > r || b < l) return 0;
        if (a <= l && r <= b) return node[i];
        
        int mid = l + r >> 1;
        return max(query(i << 1, l, mid, a, b), query(i << 1 | 1, mid + 1, r, a, b));
    }
} it;

void dfs (int u, int p) {
    dp[u] = max(1, 1 + it.query(1, 1, cnt, 1, mm[a[u]] - 1));
    last[mm[a[u]]].push_back(dp[u]);
    it.update(1, 1, cnt, mm[a[u]], dp[u]);
    
    for (auto v: g[u]) {
        if (v == p) continue;
        dfs(v, u);
    }
    
    last[mm[a[u]]].pop_back();
    it.update(1, 1, cnt, mm[a[u]], last[last.size() - 1]);
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n - 1; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    
    for (int i = 1; i <= n; i++) vec.push_back(a[i]);
    sort(vec.begin(), vec.end());
    mm[vec[0]] = ++cnt;
    for (int i = 1; i < vec.size(); i++) {
        if (vec[i] > vec[i - 1]) {
            mm[vec[i]] = ++cnt;
        }
    }
    
    for (int i = 1; i <= cnt; i++) last[i].push_back(0);
    it.init(1, 1, cnt);
    dfs(1, 1);
    for (int i = 1; i <= n; i++) cout << dp[i] << "\n";
    return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:57:46: error: request for member 'size' in 'last', which is of non-class type 'std::vector<int> [200005]'
   57 |     it.update(1, 1, cnt, mm[a[u]], last[last.size() - 1]);
      |                                              ^~~~
Language: C++

#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int n,num[200005],ans[200005];
vector<int> g[200005],dp(200005,2147483647);
void DFS(int v,int p){
	auto x=lower_bound(dp.begin(),dp.begin()+n,num[v]);
	int y=*x;
	*x=num[v];
	ans[v]=lower_bound(dp.begin(),dp.begin()+n,2147483647)-dp.begin();
	for(auto z:g[v])
		if(z!=p)
			DFS(z,v,dp);
	*x=y;
}
int main(){
	int i,from,to;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&num[i]);
	for(i=0;i<n-1;i++){
		scanf("%d%d",&from,&to);
		g[from].emplace_back(to);
		g[to].emplace_back(from); 
	}
	DFS(1,-1);
	for(i=1;i<=n;i++)
		printf("%d\n",ans[i]);
}

Compiler output:
a.cc: In function 'void DFS(int, int)':
a.cc:15:28: error: too many arguments to function 'void DFS(int, int)'
   15 |                         DFS(z,v,dp);
      |                         ~~~^~~~~~~~
a.cc:8:6: note: declared here
    8 | void DFS(int v,int p){
      |      ^~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
struct edge{int to,rev;};
using Graph=vector<vector<edge>>;
#define pb push_back
#define INF 100000000

void add_edge(int from,int to,Graph &graph)
{
    graph[from].pb((edge){to,(int)graph[to].size()});
    graph[to].pb((edge){from,(int)graph[from].size()-1});
}

void bfs(int s,Graph graph,vector<int> a)
{
    int n=graph.size();
    vector<int> d(n,INF);
    d[s]=0;
    queue<int> que;
    que.push(s);
    vector<bool> visit(n,false);
    visit[s]=true;
    vector<vector<int>> lis(n);
    lis[s].pb(a[s]);
    vector<int> ans(n);
    ans[s]=1;
    int v;
    while (!que.empty())
    {
        v=que.front();
        que.pop();
        for (int i=0;i<graph[v].size();i++)
        {
            edge &e=graph[v][i];
            if (!visit[e.to] && d[e.to]>d[v]+1)
            {
                d[e.to]=d[v]+1;
                visit[e.to]=true;
                prev[e.to]=v;
                lis[e.to]=lis[v];
                auto itr=lower_bound(lis[e.to].begin(),lis[e.to].end(),a[e.to]);
                if (itr==lis[e.to].end())
                {
                    ans[e.to]=ans[v]+1;
                    lis[e.to].pb(a[e.to]);
                }
                else 
                {
                    ans[e.to]=ans[v];
                    *itr=a[e.to];
                }
                que.push(e.to);
            }
        }
    }
    for (int i=0;i<n;i++) cout << ans[i] << endl;
    return ;
}

int main()
{
    int N;cin >> N;
    vector<int> a(N);
    for (int i=0;i<N;i++)
    {
        cin >> a[i];
    }
    Graph graph(N,vector<edge> ());
    int u,v;
    for (int i=0;i<N-1;i++)
    {
        cin >> u>>v;
        u--;v--;
        add_edge(u,v,graph);
    }
    bfs(0,graph,a);
    return 0;
}

Compiler output:
a.cc: In function 'void bfs(int, Graph, std::vector<int>)':
a.cc:41:21: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   41 |                 prev[e.to]=v;
      |                     ^