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

#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename G>
struct DLCA{
    const int Log;
    vector<int> dep;
    const G &g;
    vector<vector<int>> table;
    explicit DLCA(const G &g):g(g),dep(g.size()),Log(32-__builtin_clz(g.size())){
        table.assign(Log,vector<int>(g.size(),-1));
    }
    //各点に番号付
    void dfs(int idx,int par,int d){
        table[0][idx]=par;
        dep[idx]=d;
        for(auto &to:g[idx]){
            if(to!=par)dfs(to,idx,d+1);
        }
    }
    //構築
    void build(){
        dfs(0,-1,0);
        for(int k=0;k<Log-1;k++){
           for(int i=0;i<table[k].size();i++){
               if(table[k][i]==-1)table[k+1][i]=-1;
               else table[k+1][i]=table[k][table[k][i]];
           }
        }
    }
    //２点の最小共通祖先を探す
    int query(int u,int v){
       if(dep[u]>dep[v])swap(u,v);
       for(int i=Log-1;i>=0;i--){
           if(dep[v]-dep[u]&(1<<i))v=table[i][v];
       }
       if(u==v)return u;
       for(int i=Log-1;i>=0;i--){
           if(table[i][u]!=table[i][v]){
               u=table[i][u];
               v=table[i][v];
           }
       }
       return table[0][u];
    }
    //２点間距離
    int dist(int u,int v){
        int par=query(u,v);
        return abs(dep[u]-dep[par])+abs(dep[v]-dep[par]);
    }
};
int main(){
  int n,u,v;
  cin>>n>>u>>v;
  u--;v--;
  V<V<int>> g(n);
  for(int i=0;i<n-1;i++){
      int a,b;
      cin>>a>>b;
      a--;b--;
      g[a].push_back(b);
      g[b].push_back(a);
  }
  DLCA<V<V<int>>> t(g);
  t.build();
  int l,r,par=t.query(u,v),c;int dispar=t.dist(u,par),ans=t.dist(v,par)-1;
  for(int i=0;i<n;i++){
      l=t.dist(u,i),r=t.dist(i,v),c=t.dist(par,i);
      if(dispar+c==l)continue;
      if(l<r){
          chmax(ans,r-1);
      }
  }
  cout<<ans<<"\n";
}

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

#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;


int main() {
    int n, u, v; cin >> n >> u >> v;
    vector<vector<int>> g(n+1);
    rep(i, n-1){
        int a, b; cin >> a >> b;
        g.at(a).push_back(b);
        g.at(b).push_back(a);
    }

    vector<int> distU(n+1, -1);
    vector<int> distV(n+1, -1);
    queue<int> qu, qv;
    qu.push(u);
    qv.push(v);
    
    distU.at(u) = 0;
    distV.at(v) = 0;

    while(!qu.empty()){
        int t = qu.front();
        qu.pop();

        for(auto a:g.at(t)){
            if(distU.at(a)!=-1) continue;
            distU.at(a) = distU.at(t) + 1;
            qu.push(a);
        }
    }

    while(!qv.empty()){
        int t = qv.front();
        qv.pop();

        for(auto a:g.at(t)){
            if(distV.at(a)!=-1) continue;
            distV.at(a) = distV.at(t) + 1;
            qv.push(a);
        }
    }

    int fart = u;
    ll dist = 0;
    for(int i=1; i<=n; i++){
        if(distU.at(i)<distV.at(i)){
            if(dist<distU.at(i)){
                dist = distU.at(i);
                fart = i;
            }
        }
    }

    dump(fart);
    if(fart==u){
        if(distV.at(fast)==1) cout << 0 << endl;
        else cout << 1 << endl;
    }
    else{
        cout << distV.at(fart) - 1 << endl;
    }

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:62:21: error: 'fast' was not declared in this scope; did you mean 'fart'?
   62 |         if(distV.at(fast)==1) cout << 0 << endl;
      |                     ^~~~
      |                     fart
Language: C++

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void dfs(int v,  vi &res, const vii &tree) {
  for(int nv : tree[v]) {
    if(res[nv] != inf) continue;
    res[nv] = res[v]+1;
    dfs(nv, res, tree);
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, u, v;
  cin >> n >> u >> v;
  u--; v--;
  vii tree(n);
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  vi t(n,inf), a(n,inf);
  t[u] = 0, a[v] = 0;
  dfs(u,t,tree);
  dfs(v,a,tree);
  int ans = 0;
  rep(i,n) {
    if(t[i]+1 > a[i]) continue;
    int d = a[i];
    if(sz(tree[i]) == 1) --;
    chmax(ans, d);
  }
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:68:28: error: expected primary-expression before ';' token
   68 |     if(sz(tree[i]) == 1) --;
      |                            ^
Language: C++

#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;

int main(){
  int n, u, v;
  cin>>n>>u>>v;
  map<int,vector<int>> m;
  for(int i=0; i+1<n; i++) {
    int a, b;
    cin>>a>>b;
    if(m.find(a)==m.end()) {
      m[a] = vector<int>();
      m[a].push_back(b);
      m[b] = vector<int>();
      m[b].push_back(a);
    } else {
      m[a].push_back(b);
      m[b].push_back(a);
    }
  }
  queue<int> q;
  q.push(v);
  vector<int> vis(n,0);
  vector<int> level(n,0);
  vis[v-1] = 1;
  while(!q.empty()) {
    int now = q.front();
    q.pop();
    l++;
    for(auto next : m[now]) {
      if(vis[next-1]==1) continue;
      q.push(next);
      vis[next-1] = 1;
      level[next-1] = level[now-1]+1;
    }
  }
  vector<int> lev(n,0);
  l = 0;
  rep(i,n) vis[i] = 0;
  vis[u-1] = 1;
  q.push(u);
  while(!q.empty()) {
    int now = q.front();
    q.pop();
    for(auto next : m[now]) {
      if(vis[next-1]==1) continue;
      q.push(next);
      vis[next-1] = 1;
      lev[next-1] = lev[now-1]+1;
    }
  }
  int ans = 0;
  rep(i,n) {
    if(level[i] > lev[i])
      ans = max(ans, level[i]-1);
  }
  std::cout << ans << std::endl;
  // std::cout << level << std::endl;
  // std::cout << lev << std::endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:40:5: error: 'l' was not declared in this scope
   40 |     l++;
      |     ^
a.cc:49:3: error: 'l' was not declared in this scope
   49 |   l = 0;
      |   ^
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;
vector<vector<int> > ki;
vector<int> pat;
vector<int> p;

int pt(int now,int pa){
    if(!ki[now].size()){
        pat[now]=0;
        return 0;
    }
    int tmp=0;
    rep(i,ki[now].size()){
        if(ki[now][i]==pa) continue;
        p[ki[now][i]]=now;
        tmp=max(pt(ki[now][i],now)+1,tmp);
    }
    pat[now]=tmp;
    return pat[now];
}

int main(){
  	int n,u,v; cin >> n >> u >> v;
    u--; v--;
    ki.resize(n);
    pat.resize(n);
    p.resize(n);
    rep(i,n-1){
        int a,b; cin >> a >> b;
        a--; b--;
        ki[a].push_back(b);
        ki[b].push_back(a);
        visited[i]=0;
    }
    int d=pt(v,-1);
    int dis=0;
    int tmpu=u;
    while(tmpu!=v){
        tmpu=p[tmpu];
        dis++;
    }
    int md=0;
    tmpu=u;
    int nowdis=dis;
    rep(i,((dis-1)/2)+1){
        if(md<=pat[tmpu]+nowdis-1+i){
            md=pat[tmpu]+nowdis-1+i;
        }
        tmpu=p[tmpu];
        nowdis-=2;
    }
    cout << md << endl;
return 0;
}




Compiler output:
a.cc: In function 'int main()':
a.cc:40:9: error: 'visited' was not declared in this scope
   40 |         visited[i]=0;
      |         ^~~~~~~
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;
vector<vector<int> > ki;
vector<int> pat;
vector<int> p;

int pt(int now,int pa){
    if(!ki[now].size()){
        pat[now]=0;
        return 0;
    }
    int tmp=0;
    rep(i,ki[now].size()){
        if(ki[now[i]==pa]) continue;
        p[ki[now][i]]=now;
        tmp=max(pt(ki[now][i],now)+1,tmp);
    }
    pat[now]=tmp;
    return pat[now];
}

int main(){
  	int n,u,v; cin >> n >> u >> v;
    u--; v--;
    ki.resize(n);
    pat.resize(n);
    visited.resize(n);
    p.resize(n);
    rep(i,n-1){
        int a,b; cin >> a >> b;
        a--; b--;
        ki[a].push_back(b);
        ki[b].push_back(a);
        visited[i]=0;
    }
    int d=pt(v,-1);
    int dis=0;
    int tmpu=u;
    while(tmpu!=v){
        tmpu=p[tmpu];
        dis++;
    }
    int md=0;
    tmpu=u;
    int nowdis=dis;
    rep(i,((dis-1)/2)+1){
        if(md<=pat[tmpu]+nowdis-1+i){
            md=pat[tmpu]+nowdis-1+i;
        }
        tmpu=p[tmpu];
        nowdis-=2;
    }
    cout << md << endl;
return 0;
}




Compiler output:
a.cc: In function 'int pt(int, int)':
a.cc:21:18: error: invalid types 'int[int]' for array subscript
   21 |         if(ki[now[i]==pa]) continue;
      |                  ^
a.cc: In function 'int main()':
a.cc:34:5: error: 'visited' was not declared in this scope
   34 |     visited.resize(n);
      |     ^~~~~~~
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353

vector<vector<ll>> connec(110000);
vector<ll> l1(110000,0);
vector<ll> reached1(110000, false);
vector<ll> l2(110000,0);

void dfs1(ll x){
	//cout << "dfs1" << x << endl;
	reached1[x] = true;
	if (connec[x].size()!=0){
		REP(i,connec[x].size()){
			if (reached1.at(connec[x][i])==false){
				//cout << "つながり" << connec[x][i] << endl;
				l1.at(connec[x][i]) = l1.at(x)+1;
				dfs1(connec[x][i]);
			}
		}
	}
	return;
}

void dfs2(ll x){
	//cout << "dfs2" << x << endl;
	if (l2.at(x)!=-1){
		ll cnter = l2.at(x)+1;
		REP(i,connec[x].size()){
			if (l2.at(connec[x][i])==-1){
				continue;
			}
			else if (l1.at(connec[x][i]) <= cnter){
				continue;
			}
			else{
				//cout << "つながり" << connec[x][i] << endl;
				l2.at(connec[x][i]) = cnter;
				dfs2(connec[x][i]);
			}
		}
	}
	return;
}


int main(){
	ll n, u, v; cin >> n >> u >> v;
	REP(i,n){
		ll a, b; cin >> a >> b;
		connec[a-1].pb(b-1);
		connec[b-1].pb(a-1);
	}
	dfs1(v-1);
	dfs2(u-1);
	ll ans = 0;
	REP(i,n) {
		ans = max(ans,l2.at(i));
	}
	if (l2.at(i) == l1.at(i)){
		ans ++;
	}
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:68:19: error: 'i' was not declared in this scope
   68 |         if (l2.at(i) == l1.at(i)){
      |                   ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353

vector<vector<ll>> connec(110000);
vector<ll> l1(110000,0);
vector<ll> reached1(110000, false);
vector<ll> l2(110000,0);

void dfs1(ll x){
	cout << "dfs1" << x << endl;
	reached1[x] = true;
	if (connec[x].size()!=0){
		REP(i,connec[x].size()){
			if (reached1.at(connec[x][i])==false){
				cout << "つながり" << connec[x][i] << endl;
				l1.at(connec[x][i]) = l1.at(x)+1;
				dfs1(connec[x][i]);
			}
		}
	}
	return;
}

void dfs2(ll x){
	cout << "dfs2" << x << endl;
	if (l2.at(x)!=-1){
		ll cnter = l2.at(x)+1;
		REP(i,connec[x].size()){
			if (l2.at(connec[x][i])==-1){
				continue;
			}
			else if (l1.at(connec[x][i]) <= cnter){
				continue;
			}
			else{
				cout << "つながり" << connec[x][i] << endl;
				l2.at(connec[x][i]) = cnter;
				dfs2(connec[x][i]);
			}
		}
	}
	return;
}


int main(){
	ll n, u, v; cin >> n >> u >> v;
	REP(i,n){
		ll a, b; cin >> a >> b;
		connec[a-1].pb(b-1);
		connec[b-1].pb(a-1);
	}
	dfs1(v-1);
	dfs2(u-1);
	ll ans = 0;
	REP(i,n) {
		ans = max(ans,l2.at(i));
	}
	if (l2.at(i) == l1.at(i)){
		ans ++;
	}
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:68:19: error: 'i' was not declared in this scope
   68 |         if (l2.at(i) == l1.at(i)){
      |                   ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353

vector<vector<ll>> connec(110000);
vector<ll> l1(110000,0);
vector<ll> reached1(110000, false);
vector<ll> l2(110000,0);

void dfs1(ll x){
	cout << "dfs1" << x << endl;
	reached1[x] = true;
	if (connec[x].size()!=0){
		REP(i,connec[x].size()){
			if (reached1.at(connec[x][i])==false){
				cout << "つながり" << connec[x][i] << endl;
				l1.at(connec[x][i]) = l1.at(x)+1;
				dfs1(connec[x][i]);
			}
		}
	}
	return;
}

void dfs2(ll x){
	cout << "dfs2" << x << endl;
	if (l2.at(x)!=-1){
		ll cnter = l2.at(x)+1;
		REP(i,connec[x].size()){
			if (l2.at(connec[x][i])==-1){
				continue;
			}
			else if (l1.at(connec[x][i]) <= cnter){
				continue;
			}
			else{
				cout << "つながり" << connec[x][i] << endl;
				l2.at(connec[x][i]) = cnter;
				dfs2(connec[x][i]);
			}
		}
	}
	return;
}


int main(){
	ll n, u, v; cin >> n >> u >> v;
	REP(i,n){
		ll a, b; cin >> a >> b;
		connec[a-1].pb(b-1);
		connec[b-1].pb(a-1);
	}
	dfs1(v-1);
	dfs2(u-1);
	ll ans = 0;
	REP(i,n) {
		ans = max(ans,l2.at(i));

	}
	if (l2.at(i) == l1.at(i)){
		ans += 1
	}
	cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:69:19: error: 'i' was not declared in this scope
   69 |         if (l2.at(i) == l1.at(i)){
      |                   ^
a.cc:70:25: error: expected ';' before '}' token
   70 |                 ans += 1
      |                         ^
      |                         ;
   71 |         }
      |         ~
Language: C++

#include<iostream>
#include<vector>
using namespace std;
vector<vector<int>> c(10010,vector<int> (0));
int N;

//既に探索した部分をboolの配列で表現したところREとなった
void DFS(int p,int ans,int pp,vector<int> &d){
  d.at(p)=ans;
  for(int i=0;i<c.at(p).size();i++){
    if(c.at(p).at(i)==pp){continue;}
    DFS(c.at(p).at(i),ans+1,b,d);
  }
  return;
}

vector<int> dist(int p){
  vector<int> d(N);
  DFS(p,0,-1,d);
  return d;
}

int main(){
  int T,A,ans=0;
  
  cin>>N>>T>>A;
  T--;A--;
  
  int s,t;
  for(int i=0;i<N-1;i++){
    cin>>s>>t;
    s--;t--;
    c.at(s).push_back(t);
    c.at(t).push_back(s);
  }
  
  vector<int> Td(N),Ad(N);
  Td=dist(T);
  Ad=dist(A);
  
  for(int i=0;i<N;i++){
    if(Td[i]<Ad[i]){ans=max(ans,Ad[i]-1);}
  }
  cout<<ans;
}

Compiler output:
a.cc: In function 'void DFS(int, int, int, std::vector<int>&)':
a.cc:12:29: error: 'b' was not declared in this scope
   12 |     DFS(c.at(p).at(i),ans+1,b,d);
      |                             ^
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

void dfs(vector<vector<ll>> &tree, ll now, ll bf, vector<ll> &ans, ll o, vector<ll> &leaf, bool mode){
	bool flag = true;
	for(ll i : tree.at(now)){
		if(i == bf) continue;
		ans.at(i) = ans.at(now) + 1;
		flag = false;
		if(i == o){
			leaf.push_back(i);
			continue;
		}
		dfs(tree, i, now, ans, o, leaf, mode);
	}
	if(mode == true && flag == true) leaf.push_back(now);
}

ll main(){
	ll n, u, v;
	cin >> n >> u >> v;
	u--; v--;
	vector<vector<ll>> tree(n, vector<ll>());
	rep(i, n-1){
		ll a, b;
		cin >> a >> b;
		a--; b--;
		tree.at(a).push_back(b);
		tree.at(b).push_back(a);
	}
	//cerr << "tst" << endl;
	vector<ll> u_d(n, 1001001), v_d(n, 1001001), leaf;
	u_d.at(u) = 0;
	dfs(tree, u, -1, u_d, v, leaf, false);
	v_d.at(v) = 0;
	dfs(tree, v, -1, v_d, u, leaf, true);
	ll ans = 0;
	for(ll i : leaf){
		// cerr << i << ":" << u_d.at(i) << " " << v_d.at(i) << endl;
		if(u_d.at(i) < v_d.at(i)){
			ans = max(ans, v_d.at(i));
		}
	}
	ans--;
	cout << ans << endl;
	
	return 0;
}

Compiler output:
a.cc:26:1: error: '::main' must return 'int'
   26 | ll main(){
      | ^~
Language: C++

int N,A,B;
vector<int> E[101010];
int D[101010][2];

void dfs(int cur,int pre,int d,int id) {
	D[cur][id]=d;
	FORR(e,E[cur]) if(e!=pre) dfs(e,cur,d+1,id);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>A>>B;
	A--,B--;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	dfs(A,A,0,0);
	dfs(B,B,0,1);
	
	int ma=0;
	FOR(i,N) if(D[i][0]<D[i][1]) ma=max(ma,D[i][1]-1);
	cout<<ma<<endl;
	
}

Compiler output:
a.cc:2:1: error: 'vector' does not name a type
    2 | vector<int> E[101010];
      | ^~~~~~
a.cc: In function 'void dfs(int, int, int, int)':
a.cc:7:14: error: 'e' was not declared in this scope
    7 |         FORR(e,E[cur]) if(e!=pre) dfs(e,cur,d+1,id);
      |              ^
a.cc:7:16: error: 'E' was not declared in this scope
    7 |         FORR(e,E[cur]) if(e!=pre) dfs(e,cur,d+1,id);
      |                ^
a.cc:7:9: error: 'FORR' was not declared in this scope
    7 |         FORR(e,E[cur]) if(e!=pre) dfs(e,cur,d+1,id);
      |         ^~~~
a.cc: In function 'void solve()':
a.cc:11:28: error: 'string' was not declared in this scope
   11 |         int i,j,k,l,r,x,y; string s;
      |                            ^~~~~~
a.cc:13:9: error: 'cin' was not declared in this scope
   13 |         cin>>N>>A>>B;
      |         ^~~
a.cc:15:9: error: 'FOR' was not declared in this scope
   15 |         FOR(i,N-1) {
      |         ^~~
a.cc:25:9: error: 'cout' was not declared in this scope
   25 |         cout<<ma<<endl;
      |         ^~~~
a.cc:25:19: error: 'endl' was not declared in this scope
   25 |         cout<<ma<<endl;
      |                   ^~~~
Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;

vector<int> to[100005];
vector<int> dist;
int n;

void dfs(int v, int s = 0, int p = -1) {
	dist[v] = s;
	for (int u : to[v]) {
		if (u == p) continue;
		dfs(u, s + 1, v);
	}
}

vector<int> calcDist(int s) {
	dist = vector<int>(n);
	dfs(s);
	return dist;
}

int main() {
	int u, v;
	cin >> n >> u >> v;
	--u; --v;
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	int ans = 0;
	vector<int> A = calcDist(u);
	vector<int> T = calcDist(v);
	for (int i = 0; i < n; ++i) {
		if (A[i] < T[i]) {
			ans = max(ans, T[i]-1);
		}
	}
	cout << mx << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:42:17: error: 'mx' was not declared in this scope
   42 |         cout << mx << endl;
      |                 ^~
Language: C++

#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

//各桁の和を出力
long long Sum(long long n) {
  long long m = 0;
  while (n) {
    m += n % 10;
    n /= 10;
  }
  return m;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void Comuse() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

#define comuse Comuse()
// nCk(comuseを使え)
long long combi(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// pCk(comuseを使え)
long long perm(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] % MOD) % MOD;
}

//最小公倍数(aとbの)
long long lcm(long long a, long long b) {
  long long n;
  n = a / __gcd(a, b) * b;
  return n;
}

// auto A = div(n)
vector<long long> div(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

//(aのn乗をmodで割ったあまり)
long long modpow(long long a, long long n, long long mod) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * a % mod;
    }

    a = a * a % mod;

    n >>= 1;
  }

  return ans;
}

void solve();

const int MAX_N = 131072;
// segment tree
int NN;
int seg[MAX_N * 2 - 1];
void seguse() {
  for (int i = 0; i < 2 * NN - 1; i++) {
    seg[i] = INT_MAX;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;
  solve();
}

///////////////////////////////////////////////////////////

int N, takahashi, aoki;
vector<bool> used(1000000);
vector<bool> used2(1000000);
vector<int> route;
bool correctPath = false;
int halfSize;
int Max = 0;
int to;
int counter = 0;

void searchPath(){
 if(counter >= 10000){
   return
 }
  counter++;
  searchPath();
  return;
}


void solve() {
  searchPath();
}

Compiler output:
a.cc: In function 'void searchPath()':
a.cc:129:2: error: expected primary-expression before '}' token
  129 |  }
      |  ^
a.cc:128:10: error: expected ';' before '}' token
  128 |    return
      |          ^
      |          ;
  129 |  }
      |  ~
Language: C++

#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


ll N, U, V;
vector<ll> g[MAX];
ll ud[MAX], vd[MAX];

void dijkstra(ll s, ll* d) {
  ll i, u;
  ll clr[MAX];
  for(i=0; i<N; i++) {
    d[i]=INF;
    clr[i]=0;
  }
  priority_queue<P> q;
  q.push(P(0, s));
  d[s]=0;
  
  while(q.size()) {
    P f=q.top(); q.pop();
    u=f.sc;
    
    clr[u]=1;
    if(d[u]<-f.ft) continue;
    
    for(i=0; i<g[u].size(); i++) {
      ll v=g[u][i];
      if(clr[v]==0 && d[v]>d[u]+e.w) {
        d[v]=d[u]+1;
        q.push(P(-d[v], v));
      }
    }
  }
}

int main(void) {
  cin >> N >> U >> V;
  U--; V--;
  ll i;
  
  for(i=0; i<N-1; i++) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  dijkstra(U, ud);
  dijkstra(V, vd);
  
  ll ans=0;
  for(i=0; i<N; i++)
    if(vd[i]>ud[i])
      chmax(ans, vd[i]-1);
  
  pt(ans);
}


Compiler output:
a.cc: In function 'void dijkstra(ll, ll*)':
a.cc:40:33: error: 'e' was not declared in this scope
   40 |       if(clr[v]==0 && d[v]>d[u]+e.w) {
      |                                 ^
Language: C++

#include<iostream>
#include<vector>
using namespace std;

int N,u,v;

void DFS(int p,int d=0,vector<vector<int>> &m,int s,vector<int> &dist){
  dist[p]=d;
  for(int i:m[p]){
    if(i==s){continue;}
    DFS(i,d+1,m,p);
  }
}

vector<int> calculate(int p,vector<vector<int>> &m){
  vector<int> dist(N);
  dfs(p,int d=0,m,int s=-1,dist)
  return dist;
}

int main(){
  int ans=0;
  cin>>N>>u>>v;
  vector<vector<int>> m(N,vector<int>(0));
  vector<int> ud(N),vd(N)
  
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    m.at(a).push_back(b);
    m.at(b).push_back(a);
  }
  
  ud=calculate(u,m);
  vd=calculate(v,m);
  
  for(int i=0;i<ud.size();i++){
    if(ud.at(i)>vd.at(i)){
      ans=max(ans,ud.at(i));
    }
  }
  
  cout<<ans-1<<endl;
}
  

Compiler output:
a.cc:7:45: error: default argument missing for parameter 3 of 'void DFS(int, int, std::vector<std::vector<int> >&, int, std::vector<int>&)'
    7 | void DFS(int p,int d=0,vector<vector<int>> &m,int s,vector<int> &dist){
      |                        ~~~~~~~~~~~~~~~~~~~~~^
a.cc:7:20: note: ...following parameter 2 which has a default argument
    7 | void DFS(int p,int d=0,vector<vector<int>> &m,int s,vector<int> &dist){
      |                ~~~~^~~
a.cc:7:51: error: default argument missing for parameter 4 of 'void DFS(int, int, std::vector<std::vector<int> >&, int, std::vector<int>&)'
    7 | void DFS(int p,int d=0,vector<vector<int>> &m,int s,vector<int> &dist){
      |                                               ~~~~^
a.cc:7:66: error: default argument missing for parameter 5 of 'void DFS(int, int, std::vector<std::vector<int> >&, int, std::vector<int>&)'
    7 | void DFS(int p,int d=0,vector<vector<int>> &m,int s,vector<int> &dist){
      |                                                     ~~~~~~~~~~~~~^~~~
a.cc: In function 'std::vector<int> calculate(int, std::vector<std::vector<int> >&)':
a.cc:17:9: error: expected primary-expression before 'int'
   17 |   dfs(p,int d=0,m,int s=-1,dist)
      |         ^~~
a.cc:17:19: error: expected primary-expression before 'int'
   17 |   dfs(p,int d=0,m,int s=-1,dist)
      |                   ^~~
a.cc:17:3: error: 'dfs' was not declared in this scope
   17 |   dfs(p,int d=0,m,int s=-1,dist)
      |   ^~~
a.cc:19:1: warning: no return statement in function returning non-void [-Wreturn-type]
   19 | }
      | ^
a.cc: In function 'int main()':
a.cc:27:3: error: expected ',' or ';' before 'for'
   27 |   for(int i=0;i<N;i++){
      |   ^~~
a.cc:27:15: error: 'i' was not declared in this scope
   27 |   for(int i=0;i<N;i++){
      |               ^
Language: C++

from collections import deque

def BFS(s):
 tree=[[] for i in range(n)]
 for i in list:
  tree[i[0]-1].append(i[1]-1)
  tree[i[1]-1].append(i[0]-1)

 dist=[-1 for i in range(n)]
 dist[s-1]=0

 que=deque()
 que.append(s-1)
 while que:
  x=que.popleft()
  for p in tree[x]:
   if dist[p]==-1:
    que.append(p)
    dist[p]=dist[x]+1
 return dist

n,u,v=map(int,input().split())
list=[list(map(int,input().split())) for i in range(n-1)]

u_dist=BFS(u)
v_dist=BFS(v)

l=0
for u_d,v_d in zip(u_dist,v_dist):
 if u_d<v_d:
  l=max(l,v_d)

print(l-1)

Compiler output:
a.cc:1:1: error: 'from' does not name a type
    1 | from collections import deque
      | ^~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
int n,a[100001],next[100001],u;
long long f[100001],x,y;
void dfs(int i)
{
	for(int j=1;j<=u;j++)
	{
		if(a[j]==i&&f[next[j]]>f[i]+1)
		{
			f[next[j]]=f[i]+1;
			dfs(next[j]);
		}
	}
	return;
}
int main()
{
	int q,w;
	cin>>n>>x>>y;
	for(int i=1;i<n;i++)
	{
		cin>>q>>w;
		a[++u]=q;
		next[u]=w;
		f[i]=9999999999;
	}
	f[n]=9999999999;
	f[x]=0;
	dfs(x);
	cout<<f[y]/2;
	return 0;
}

Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:9:31: error: reference to 'next' is ambiguous
    9 |                 if(a[j]==i&&f[next[j]]>f[i]+1)
      |                               ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:3:17: note:                 'int next [100001]'
    3 | int n,a[100001],next[100001],u;
      |                 ^~~~
a.cc:11:27: error: reference to 'next' is ambiguous
   11 |                         f[next[j]]=f[i]+1;
      |                           ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:3:17: note:                 'int next [100001]'
    3 | int n,a[100001],next[100001],u;
      |                 ^~~~
a.cc:12:29: error: reference to 'next' is ambiguous
   12 |                         dfs(next[j]);
      |                             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:3:17: note:                 'int next [100001]'
    3 | int n,a[100001],next[100001],u;
      |                 ^~~~
a.cc: In function 'int main()':
a.cc:25:17: error: reference to 'next' is ambiguous
   25 |                 next[u]=w;
      |                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:3:17: note:                 'int next [100001]'
    3 | int n,a[100001],next[100001],u;
      |                 ^~~~
Language: C++

/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

const int NN=100005;
vector<ll> t[NN];
ll d[NN][2];

void dfs(ll cur,ll pre,ll dist,ll type){
  d[c][type]=dist;
  for(auto a:t[cur]) if(a!=pre) dfs(a,cur,dist+1,type);
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,u,v;
  cin>>n>>u>>v;v--;u--;
  rep(i,n-1){
    ll x,y;
    cin>>x>>y;x--;y--;
    t[x].push_back(y);
    t[y].push_back(x);
  }
  dfs(u,-1,0,0);
  dfs(v,-1,0,1);
  ll ans=0;
  rep(i,n) if(d[i][0]<d[i][1]) chmax(ans,d[i][1]-1);
  cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'void dfs(ll, ll, ll, ll)':
a.cc:142:5: error: 'c' was not declared in this scope
  142 |   d[c][type]=dist;
      |     ^
Language: C++

/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

const int NN=100005;
vector<ll> t[NN];
ll d[NN][2];

void dfs(ll cur,ll pre,ll dist,ll type){
  d[c][type]=dist;
  for(auto a:t[cur]) if(a!=pre) dfs(a,cur,dist+1,type);
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,u,v;
  cin>>n>>u>>v;v--;u--;
  rep(i,n-1){
    ll x,y;
    cin>>x>>y;x--;y--;
    t[x].push_back(y);
    t[y].push_back(x);
  }
  dfs(u,-1,0,0);
  dfs(v,-1,0,1);
  ll ans=0;
  rep(i,n) if(d[i][0]<d[i][1]) chmax(ans,d[i][1]-1);
  
}

Compiler output:
a.cc: In function 'void dfs(ll, ll, ll, ll)':
a.cc:142:5: error: 'c' was not declared in this scope
  142 |   d[c][type]=dist;
      |     ^
Language: C++

#include<iostream>
#include<vector>
#include<queue>
using namespace std;
const int BUF = 100005;


int nNode, s, t;
vector<int> adj[BUF];

void read() {
    for (int i = 0; i < BUF; ++i) adj[i].clear();

    cin >> nNode >> s >> t;
    --s;
    --t;
    for (int i = 0; i < nNode - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
}


void bfs(int bgn, int cost[BUF]) {
    queue<int> Q;
    
    cost[bgn] = 0;
    Q.push(bgn);

    while (!Q.empty()) {
        int cur = Q.front();
        Q.pop();

        for (int i = 0; i < adj[cur].size(); ++i) {
            int nex = adj[cur][i];
            if (cost[nex] == -1) {
                cost[nex] = cost[cur] + 1;
                Q.push(nex);
            }
        }
    }
}


void work() {
    int costS[BUF];
    int costT[BUF];
    memset(costS, -1, sizeof(costS));
    memset(costT, -1, sizeof(costT));
    bfs(s, costS);
    bfs(t, costT);

    int ans = 0;
    for (int i = 0; i < nNode; ++i) {
        if (costS[i] < costT[i]) continue;
        
        if (costS[i] % 2 == costT[i] % 2) {
            if (adj[i].size() == 1)
                ans = max(ans, costS[i] - 2);
            else
                ans = max(ans, costS[i]);
        } else {
            ans = max(ans, costS[i] - 1);
        }
    }
    cout << ans << endl;
}


int main() {
    read();
    work();
    return 0;
}


Compiler output:
a.cc: In function 'void work()':
a.cc:52:5: error: 'memset' was not declared in this scope
   52 |     memset(costS, -1, sizeof(costS));
      |     ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include<queue>
  +++ |+#include <cstring>
    4 | using namespace std;
Language: C++

#include<iostream>
#include<fstream>
#include<vector>


std::vector<int> depth_u;
std::vector<int> depth_v;
int cnt = 0;

void dfs(const std::vector< std::vector< int > > &Graph, int v, int p, int d, std::vector<int>& depth){ 
  depth[v] = d;

  for(auto next_v : Graph[v]){
    if(next_v == p){
      continue;
    }
    dfs(Graph, next_v, v, d+1, depth);
  }
}
int main(){
  

  int N, u, v, a, b, cnt;
  std::cin >> N >> u >> v;
  std::vector< std::vector< int > > Graph;
  Graph.resize(N+1);

  for(int i = 0; i < N-1; i++){
    std::cin >> a >> b;
    Graph[a].push_back(b);
    Graph[b].push_back(a);
  }

  int cn = 0;
  depth_u.resize(N+1);
  depth_v.resize(N+1);
  
  dfs(Graph, u, -1, 0, depth_u);
  dfs(Graph, v, -1, 0, depth_v);

  std::vector< int > array;
  for(int i = 0; i < N+2; i++){
    if( depth_v[i] > depth_u[i] ){
      array.push_back(depth_v[i]);
    }
  }
  std::cout << *std::max_element(array.begin(), array.end()) - 1 << std::endl;

  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:47:22: error: 'max_element' is not a member of 'std'; did you mean 'tuple_element'?
   47 |   std::cout << *std::max_element(array.begin(), array.end()) - 1 << std::endl;
      |                      ^~~~~~~~~~~
      |                      tuple_element
Language: C++

#include <stdlib.h>
#include <stdio.h>
 
#define MAXN 100000
 
struct list {
	int n, c;
	int *edges;
} verts[MAXN];
 
void add_list(struct list *l, int v) {
	if (l->n+1 > l->c) {
		if (!l->c)
			l->c = 1;
		l->c *= 2;
		l->edges = realloc(l->edges, (size_t)l->c * sizeof *l->edges);
	}
	l->edges[l->n++] = v;
}
void del_list(struct list *l, int v) {
	int tail = 0;
	for (int head = 0; head < l->n; head++) {
		if (l->edges[head] == v)
			continue;
		l->edges[tail++] = l->edges[head];
	}
	l->n--;
}
 
void add_edge(int a, int b) {
	add_list(&verts[a], b);
	add_list(&verts[b], a);
}
 
int calc_dists_rec(int c, int dists[MAXN], int dist) {
	if (dists[c] != -1)
		return -1;
	dists[c] = dist;
 
	int best = dist;
	for (int i = 0; i < verts[c].n; i++) {
		int d = calc_dists_rec(verts[c].edges[i], dists, dist+1);
		if (d > best)
			best = d;
	}
	return best;
}
 
int calc_dists(int s, int dists[MAXN]) {
	for (int i = 0; i < MAXN; i++)
		dists[i] = -1;
	return calc_dists_rec(s, dists, 0);
}
 
int udist[MAXN], vdist[MAXN], cdist[MAXN];
 
int crit_point(int s) {
	if (udist[s] >= vdist[s])
		return s;
 
	int bestv = -1, bestd = MAXN;
	for (int i = 0; i < verts[s].n; i++) {
		int n = verts[s].edges[i];
		if (vdist[n] < bestd) {
			bestv = n;
			bestd = vdist[n];
		}
	}
 
	return crit_point(bestv);
}
 
int main(void) {
	int n, u, v;
	scanf("%d%d%d", &n, &u, &v);
	u--; v--;
 
	for (int i = 0; i < n-1; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		add_edge(a-1, b-1);
	}
 
	calc_dists(u, udist);
	calc_dists(v, vdist);
	int crit = crit_point(u);
 
	int before;
	for (before = 0; before < verts[crit].n-1; before++) {
		int da = udist[verts[crit].edges[before]];
		int db = udist[verts[crit].edges[before+1]];
		if (da < db)
			break;
	}
	int befv = verts[crit].edges[before];
	del_list(&verts[befv], crit);
	int max = calc_dists(befv, cdist);
 
	printf("%d\n", udist[befv] + max + (udist[crit] == vdist[crit]));
	
	
	for(int i=0;i<11451419;i++){
		char *p;
		*p='a';
	}
 
	for (int i = 0; i < n; i++)
		free(verts[i].edges);
}


Compiler output:
a.cc: In function 'void add_list(list*, int)':
a.cc:16:35: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
   16 |                 l->edges = realloc(l->edges, (size_t)l->c * sizeof *l->edges);
      |                            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                   |
      |                                   void*
Language: C++


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


vector <ll> graph[N];
ll alt1[N], alt2[N];



void dfs1(ll u, ll p){
    for(auto x1: graph[u]){
        if(x1 == p) continue;
        alt1[x1] = alt1[u] + 1;
        dfs1(x1, u);
    }
}


void dfs2(ll u, ll p){
    for(auto x1: graph[u]){
        if(x1 == p) continue;
        alt2[x1] = alt2[u] + 1;
        dfs2(x1, u);
    }
}




int main()
{
	ll n,x,y;
	cin>>n>>x>>y;
	//x-->tanshik intial position
	//y-->aloki  intial position
	for(ll i=0;i<n-1;i++)
	 { ll a,b;
	   cin>>a>>b;
	 	graph[a].push_back(b);
	 	graph[b].push_back(a);
	 }
	 
	   alt1[x] = 0;
    alt2[y] = 0;
    dfs1(x, -1);
    dfs2(y, -1);
    ll ans = 0;

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

        if(alt1[i] < alt2[i]) ans = max(ans, alt2[i] - 1);
    }

    cout << ans << endl;
 	
 }

Compiler output:
a.cc:7:19: error: 'N' was not declared in this scope
    7 | vector <ll> graph[N];
      |                   ^
a.cc:8:9: error: 'N' was not declared in this scope
    8 | ll alt1[N], alt2[N];
      |         ^
a.cc:8:18: error: 'N' was not declared in this scope
    8 | ll alt1[N], alt2[N];
      |                  ^
a.cc: In function 'void dfs1(ll, ll)':
a.cc:13:18: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   13 |     for(auto x1: graph[u]){
      |                  ^~~~~
      |                  isgraph
a.cc:15:9: error: 'alt1' was not declared in this scope
   15 |         alt1[x1] = alt1[u] + 1;
      |         ^~~~
a.cc: In function 'void dfs2(ll, ll)':
a.cc:22:18: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   22 |     for(auto x1: graph[u]){
      |                  ^~~~~
      |                  isgraph
a.cc:24:9: error: 'alt2' was not declared in this scope
   24 |         alt2[x1] = alt2[u] + 1;
      |         ^~~~
a.cc: In function 'int main()':
a.cc:41:17: error: 'graph' was not declared in this scope; did you mean 'isgraph'?
   41 |                 graph[a].push_back(b);
      |                 ^~~~~
      |                 isgraph
a.cc:45:12: error: 'alt1' was not declared in this scope
   45 |            alt1[x] = 0;
      |            ^~~~
a.cc:46:5: error: 'alt2' was not declared in this scope
   46 |     alt2[y] = 0;
      |     ^~~~
Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define PI 3.14159265
#define INF 2147483647
using namespace std;
using ll = long long;
void self_max(int &a,int b){
	a = max(a,b);
}
void self_min(int &a,int b){
	a = min(a,b);
}

int n;
vector<int> to(100005);
std::vector<int> dist;

void dfs(int V, int d = 0, int P= -1){
	dist[V] = d;
	for(int u: to[V]){
		if(u== v) continue;
		dfs(u,d+1,V);
	}
}


vector<int> calDistance(int P){
	vector<int> dist(n);
	dfs(P);
	return dist;
}



int main(){
	cin >> n;
	int T,A; cin >> T >> A;

	// buh tseguudee to array ruu hiine
	rep(i,n-1){
		int a,b; cin >> a >> b;
		to[a].push_back(b);
		to[b].push_back(a);
	}

	vector<int> distFromA = calDistance(A);
	vector<int> distFromT = calDistance(T);
	int ret = 0;
	rep(i,n){
		if(distFromA[i] < distFromT[i]){
			self_max(ret,distFromT[i]-1);
		}
	}

	cout << ret << endl;
	return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int, int)':
a.cc:20:24: error: 'begin' was not declared in this scope
   20 |         for(int u: to[V]){
      |                        ^
a.cc:20:24: note: suggested alternatives:
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166,
                 from a.cc:1:
/usr/include/c++/14/valarray:1238:5: note:   'std::begin'
 1238 |     begin(const valarray<_Tp>& __va) noexcept
      |     ^~~~~
In file included from /usr/include/c++/14/filesystem:53,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:200:
/usr/include/c++/14/bits/fs_dir.h:608:3: note:   'std::filesystem::__cxx11::begin'
  608 |   begin(recursive_directory_iterator __iter) noexcept
      |   ^~~~~
a.cc:20:24: error: 'end' was not declared in this scope
   20 |         for(int u: to[V]){
      |                        ^
a.cc:20:24: note: suggested alternatives:
/usr/include/c++/14/valarray:1265:5: note:   'std::end'
 1265 |     end(const valarray<_Tp>& __va) noexcept
      |     ^~~
/usr/include/c++/14/bits/fs_dir.h:613:3: note:   'std::filesystem::__cxx11::end'
  613 |   end(recursive_directory_iterator) noexcept
      |   ^~~
a.cc:21:24: error: 'v' was not declared in this scope
   21 |                 if(u== v) continue;
      |                        ^
a.cc: In function 'int main()':
a.cc:42:23: error: request for member 'push_back' in 'to.std::vector<int>::operator[](((std::vector<int>::size_type)a))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   42 |                 to[a].push_back(b);
      |                       ^~~~~~~~~
a.cc:43:23: error: request for member 'push_back' in 'to.std::vector<int>::operator[](((std::vector<int>::size_type)b))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'}
   43 |                 to[b].push_back(a);
      |                       ^~~~~~~~~