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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int n;
int s[100010], t[100010], w[100010];
ll dist[100010];
vector<pair<int, ll>> G[100010];

int dfs1(int u, int par) {
	ll ma = 0;
	for(auto tm : G[u]) {
		int v = tm.fi; ll cost = tm.se;
		if(v == par) continue;
		chmax(ma, dfs1(v, u) + cost);
	}
	return dist[u] = ma;
}

ll dfs2(int u, int w, int par) {
	vector<pair<int, int>> child; // (??????, ?????????????????????)
	child.pb(mp(0, -1));
	for(auto tm : G[u]) {
		int v = tm.fi; ll cost = tm.se;
		if(v == par) child.pb(mp(w + cost, v));
		else child.pb(mp(dist[v] + cost, v));
	}
	sort(all(child)); reverse(all(child));
	ll ret = child[0].fi + child[1].fi;
	for(auto tm : G[u]) {
		int v = tm.fi; ll cost = tm.se;
		if(v == par) continue;
		if(v == child[0].se) chmax(ret, dfs2(v, child[1].fi, u));
		else chmax(ret, dfs2(v, child[0].fi, u));
	}
	return ret;
}

int main(void) {
	cin >> n;
	rep(i, n - 1) cin >> s[i] >> t[i] >> w[i];
	rep(i, n - 1) G[s[i]].pb(mp(t[i], w[i]));
	rep(i, n - 1) G[t[i]].pb(mp(s[i], w[i]));
	dfs1(N / 2, -1);
	auto ret = dfs2(N / 2, 0, -1);
	printf("%lld\n", ret);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:62:14: error: 'N' was not declared in this scope
   62 |         dfs1(N / 2, -1);
      |              ^
Language: C++

#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 100000
#define INFTY (1<<30)
  
class Edge {
public:
    int t, w;
};
  
vector<Edge> G[MAX];
int n, d[MAX];
  
void bfs(int s) {
    for (int i = 0; i < n; i++)d[i] = INFTY;
    queue<int> Q;
    Q.push(s);
    d[s] = 0;
    int u;
    while (!Q.empty()) {
        u = Q.front();
        Q.pop();
        for (int i = 0; i < G[u].size(); i++) {
            Edge e = G[u][i];
            if (d[e.t] == INFTY) {
                d[e.t] = d[u] + e.w;
                Q.push(e.t);
            }
        }
    }
}
  
void solve() {
    bfs(0);
    int maxv = 0;
    int tgt = 0;
    for (int i = 0; i < n; i++) {
        if (maxv < d[i]) {
            maxv = d[i];
            tgt = i;
        }
    }
  
    bfs(tgt);
    maxv = 0;
    for (int i = 0; i < n; i++) {
        if (d[i] == INFTY)continue;
        maxv = max(maxv, d[i]);
    }
  
    cout << maxv << endl;
}
  
main() {
    int s, t, w;
    cin >> n;
  
    for (int i = 0; i < n - 1; i++) {
        cin >> s >> t >> w;
  
        G[s].push_back(Edge(t, w));
        G[t].push_back(Edge(s, w));
    }
    solve();
}


Compiler output:
a.cc:56:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   56 | main() {
      | ^~~~
a.cc: In function 'int main()':
a.cc:63:33: error: no matching function for call to 'Edge::Edge(int&, int&)'
   63 |         G[s].push_back(Edge(t, w));
      |                                 ^
a.cc:8:7: note: candidate: 'Edge::Edge()'
    8 | class Edge {
      |       ^~~~
a.cc:8:7: note:   candidate expects 0 arguments, 2 provided
a.cc:8:7: note: candidate: 'constexpr Edge::Edge(const Edge&)'
a.cc:8:7: note:   candidate expects 1 argument, 2 provided
a.cc:8:7: note: candidate: 'constexpr Edge::Edge(Edge&&)'
a.cc:8:7: note:   candidate expects 1 argument, 2 provided
a.cc:64:33: error: no matching function for call to 'Edge::Edge(int&, int&)'
   64 |         G[t].push_back(Edge(s, w));
      |                                 ^
a.cc:8:7: note: candidate: 'Edge::Edge()'
    8 | class Edge {
      |       ^~~~
a.cc:8:7: note:   candidate expects 0 arguments, 2 provided
a.cc:8:7: note: candidate: 'constexpr Edge::Edge(const Edge&)'
a.cc:8:7: note:   candidate expects 1 argument, 2 provided
a.cc:8:7: note: candidate: 'constexpr Edge::Edge(Edge&&)'
a.cc:8:7: note:   candidate expects 1 argument, 2 provided
Language: C++

#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define dumpP(p) cerr << "( " << p.first << " , " << p.second << " )" << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define SORT(c) sort((c).begin(),(c).end())
#define MIN(vec) *min_element(vec.begin(), vec.end());
#define MAX(vec) *max_element(vec.begin(), vec.end());
#define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()),vec.end());
#define IN(n,m)  (!(m.find(n) == m.end()))
#define TO_INT(vec,s) REP(i,s.length()){vec.push_back(s[i] - ‘0’);}
#define ENUM_v(vec) for (auto e : vec)
#define dump_MAP(m) for(auto itr = m.begin(); itr != m.end(); ++itr) { cerr << itr->first << " --> "  << itr->second << endl; }
#define FINDL(vec,x) (lower_bound(vec.begin(),vec.end(),x) - vec.begin())
#define FINDU(vec,x) (upper_bound(vec.begin(),vec.end(),x) - vec.begin())
#define ROUND(N) setprecision(N)
using namespace std;
constexpr long mod = 1000000007;
constexpr short shINF = 32767;
constexpr long loINF = 2147483647;
constexpr long long llINF = 9223372036854775807;
typedef long long LL;
typedef vector<long> VI;
typedef vector<VI> VVI;

template <typename T,typename D>
class Tree {
private:
	typedef struct {T node;D dist;T prev;} P;
	typedef pair<T,D> pr;
	typedef vector<pr> VP;
	vector<VP> E;
	T V;
public:
	Tree() : V(0){}
	Tree(T v) : V(v),E(v) {}

	void addEdgeDirected(long start,long goal,long weight){
		E[start].push_back(pr(goal,weight));
	}

	void addEdgeUndirected(long start,long goal,long weight){
		E[start].push_back(pr(goal,weight));
		E[goal].push_back(pr(start,weight));
	}

	pair<T,D> getDiameter(void){
		stack<P> st;
		pair<T,D> farV(V-1,0);
		st.push(P {V-1,0,-1});
		while (!st.empty()) {
			P e = st.top();
			st.pop();
			if (farV.second < e.dist) farV = pair<T,D> (e.node,e.dist);
			for ( auto &p : E[e.node]) {
				if (p.first != e.prev) st.push(P {p.first,e.dist+p.second,e.node});
			}
		}
		pair<T,D> farV2(farV.first,0);
		st.push(P {farV.first,0,-1});
		while (!st.empty()) {
			P e = st.top();
			st.pop();
			if (farV2.second < e.dist) farV2 = pair<T,D> (e.node,e.dist);
			for ( auto &p : E[e.node]) {
				if (p.first != e.prev) st.push(P {p.first,e.dist+p.second,e.node});
			}
		}

		return farV2;
	}
};

int main(void) {
	long N,s,t,w;
	cin >> N;
	Tree<long,long> tr(N);
	REP(i,N-1){
		cin >> s >> t >> w;
		tr.addEdgeUndirected(s,t,w);
	}
	auto p = tr.getDiameter();
	cout << p.second << endl;
}


Compiler output:
a.cc:16:62: error: extended character ‘ is not valid in an identifier
   16 | #define TO_INT(vec,s) REP(i,s.length()){vec.push_back(s[i] - ‘0’);}
      |                                                              ^
a.cc:16:62: error: extended character ’ is not valid in an identifier
Language: C++

#include<iostream>
#include<queu>
#include<vector>

using namespace std;

static const int MAX = 100000;
static const int INFTY = (1 << 30);

class Edte {
public:
  int t, w;
  Edge() {}
  Edge(int t, int w)
    : t(t),
    , w(w) {}
};

vector(Edge) G[MAX];
int n, d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s) {
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
  }
  queue<int> Q;
  Q.push(s);
  d[s] = 0;
  int u;
  while (!Q.empty()) {
    u = Q.front(); Q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      Edge e = G[u][i];
      if (d[e.t] == INFTY) {
        d[e.t] = d[u] + e.w;
        Q.push(e.t);
      }
    }
  }
}

void solve() {
  bfs(0);
  int maxv = 0l
  int rgt = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == INFTY) {
      continue;
    }
    if (maxv < d[i]) {
      maxv = d[i];
      tgt = i;
    }
  }

  bfs(tgt);
  maxv = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == INFTY) {
      continue;
    }
    maxv = max(maxv, d[i]);
  }

  cout << maxv << endl;
}

int main() {
  int s, t, w;
  cin >> n;

  for (int i = 0; i < n -1; i++) {
    cin >> s >> t >> w;

    G[s].push_back(Edge(t, w));
    G[t].push_back(Edge(s, w));
  }

  solve();

  return 0;
}



Compiler output:
a.cc:2:9: fatal error: queu: No such file or directory
    2 | #include<queu>
      |         ^~~~~~
compilation terminated.
Language: C++

#include<iostream>
#include<queue>
#include<vector>

using namespace std;

static const int MAX = 100000;
static const int INFTY = (1 << 30);

class Edge {
public:
  int t, w;
  Edge() {}
  Edge(int t, int w)
    : t(t),
    , w(w) {}
};

vector(Edge) G[MAX];
int n, d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s) {
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
  }
  queue<int> Q;
  Q.push(s);
  d[s] = 0;
  int u;
  while (!Q.empty()) {
    u = Q.front(); Q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      Edge e = G[u][i];
      if (d[e.t] == INFTY) {
        d[e.t] = d[u] + e.w;
        Q.push(e.t);
      }
    }
  }
}

void solve() {
  bfs(0);
  int maxv = 0l
  int rgt = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == INFTY) {
      continue;
    }
    if (maxv < d[i]) {
      maxv = d[i];
      tgt = i;
    }
  }

  bfs(tgt);
  maxv = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == INFTY) {
      continue;
    }
    maxv = max(maxv, d[i]);
  }

  cout << maxv << endl;
}

int main() {
  int s, t, w;
  cin >> n;

  for (int i = 0; i < n -1; i++) {
    cin >> s >> t >> w;

    G[s].push_back(Edge(t, w));
    G[t].push_back(Edge(s, w));
  }

  solve();

  return 0;
}



Compiler output:
a.cc: In constructor 'Edge::Edge(int, int)':
a.cc:16:5: error: expected identifier before ',' token
   16 |     , w(w) {}
      |     ^
a.cc: At global scope:
a.cc:19:14: error: expected initializer before 'G'
   19 | vector(Edge) G[MAX];
      |              ^
a.cc: In function 'void bfs(int)':
a.cc:35:25: error: 'G' was not declared in this scope
   35 |     for (int i = 0; i < G[u].size(); i++) {
      |                         ^
a.cc: In function 'void solve()':
a.cc:48:3: error: expected ',' or ';' before 'int'
   48 |   int rgt = 0;
      |   ^~~
a.cc:55:7: error: 'tgt' was not declared in this scope
   55 |       tgt = i;
      |       ^~~
a.cc:59:7: error: 'tgt' was not declared in this scope
   59 |   bfs(tgt);
      |       ^~~
a.cc: In function 'int main()':
a.cc:78:5: error: 'G' was not declared in this scope
   78 |     G[s].push_back(Edge(t, w));
      |     ^
Language: C++


#include<iostream>
#include<queue>
#include<vector>

using namespace std;

static const int MAX = 100000;
static const int INFTY = (1 << 30);

class Edge {
public:
  int t, w;
  Edge() {}
  Edge(int t, int w)
    : t(t)
    , w(w) {}
};

vector(Edge) G[MAX];
int n, d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s) {
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
  }
  queue<int> Q;
  Q.push(s);
  d[s] = 0;
  int u;
  while (!Q.empty()) {
    u = Q.front(); Q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      Edge e = G[u][i];
      if (d[e.t] == INFTY) {
        d[e.t] = d[u] + e.w;
        Q.push(e.t);
      }
    }
  }
}

void solve() {
  bfs(0);
  int maxv = 0l
  int rgt = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == INFTY) {
      continue;
    }
    if (maxv < d[i]) {
      maxv = d[i];
      tgt = i;
    }
  }

  bfs(tgt);
  maxv = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == INFTY) {
      continue;
    }
    maxv = max(maxv, d[i]);
  }

  cout << maxv << endl;
}

int main() {
  int s, t, w;
  cin >> n;

  for (int i = 0; i < n -1; i++) {
    cin >> s >> t >> w;

    G[s].push_back(Edge(t, w));
    G[t].push_back(Edge(s, w));
  }

  solve();

  return 0;
}



Compiler output:
a.cc:20:14: error: expected initializer before 'G'
   20 | vector(Edge) G[MAX];
      |              ^
a.cc: In function 'void bfs(int)':
a.cc:36:25: error: 'G' was not declared in this scope
   36 |     for (int i = 0; i < G[u].size(); i++) {
      |                         ^
a.cc: In function 'void solve()':
a.cc:49:3: error: expected ',' or ';' before 'int'
   49 |   int rgt = 0;
      |   ^~~
a.cc:56:7: error: 'tgt' was not declared in this scope
   56 |       tgt = i;
      |       ^~~
a.cc:60:7: error: 'tgt' was not declared in this scope
   60 |   bfs(tgt);
      |       ^~~
a.cc: In function 'int main()':
a.cc:79:5: error: 'G' was not declared in this scope
   79 |     G[s].push_back(Edge(t, w));
      |     ^
Language: C++


#include<iostream>
#include<queue>
#include<vector>

using namespace std;

static const int MAX = 100000;
static const int INFTY = (1 << 30);

class Edge {
public:
  int t, w;
  Edge() {}
  Edge(int t, int w)
    : t(t)
    , w(w) {}
};

vector<Edge> G[MAX];
int n, d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s) {
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
  }
  queue<int> Q;
  Q.push(s);
  d[s] = 0;
  int u;
  while (!Q.empty()) {
    u = Q.front(); Q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      Edge e = G[u][i];
      if (d[e.t] == INFTY) {
        d[e.t] = d[u] + e.w;
        Q.push(e.t);
      }
    }
  }
}

void solve() {
  bfs(0);
  int maxv = 0l
  int rgt = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == INFTY) {
      continue;
    }
    if (maxv < d[i]) {
      maxv = d[i];
      tgt = i;
    }
  }

  bfs(tgt);
  maxv = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == INFTY) {
      continue;
    }
    maxv = max(maxv, d[i]);
  }

  cout << maxv << endl;
}

int main() {
  int s, t, w;
  cin >> n;

  for (int i = 0; i < n -1; i++) {
    cin >> s >> t >> w;

    G[s].push_back(Edge(t, w));
    G[t].push_back(Edge(s, w));
  }

  solve();

  return 0;
}



Compiler output:
a.cc: In function 'void solve()':
a.cc:49:3: error: expected ',' or ';' before 'int'
   49 |   int rgt = 0;
      |   ^~~
a.cc:56:7: error: 'tgt' was not declared in this scope
   56 |       tgt = i;
      |       ^~~
a.cc:60:7: error: 'tgt' was not declared in this scope
   60 |   bfs(tgt);
      |       ^~~
Language: C++


#include<iostream>
#include<queue>
#include<vector>

using namespace std;

static const int MAX = 100000;
static const int INFTY = (1 << 30);

class Edge {
public:
  int t, w;
  Edge() {}
  Edge(int t, int w)
    : t(t)
    , w(w) {}
};

vector<Edge> G[MAX];
int n, d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s) {
  for (int i = 0; i < n; i++) {
    d[i] = INFTY;
  }
  queue<int> Q;
  Q.push(s);
  d[s] = 0;
  int u;
  while (!Q.empty()) {
    u = Q.front(); Q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      Edge e = G[u][i];
      if (d[e.t] == INFTY) {
        d[e.t] = d[u] + e.w;
        Q.push(e.t);
      }
    }
  }
}

void solve() {
  bfs(0);
  int maxv = 0;
  int rgt = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == INFTY) {
      continue;
    }
    if (maxv < d[i]) {
      maxv = d[i];
      tgt = i;
    }
  }

  bfs(tgt);
  maxv = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] == INFTY) {
      continue;
    }
    maxv = max(maxv, d[i]);
  }

  cout << maxv << endl;
}

int main() {
  int s, t, w;
  cin >> n;

  for (int i = 0; i < n -1; i++) {
    cin >> s >> t >> w;

    G[s].push_back(Edge(t, w));
    G[t].push_back(Edge(s, w));
  }

  solve();

  return 0;
}




Compiler output:
a.cc: In function 'void solve()':
a.cc:56:7: error: 'tgt' was not declared in this scope; did you mean 'rgt'?
   56 |       tgt = i;
      |       ^~~
      |       rgt
a.cc:60:7: error: 'tgt' was not declared in this scope; did you mean 'rgt'?
   60 |   bfs(tgt);
      |       ^~~
      |       rgt
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

static const int MAX_N = 1e5 + 10;
static const int INFTY = (1<<30);

struct Edge{int t, w;};

vector<Edge> G[MAX_N];
int H[MAX_N][MAX_N];
int n, h[MAX_N];

int height(int s, int idx){
	Edge e = G[s][idx];
	if (H[s][e.t]>=0) return H[s][e.t];
	H[s][e.t] = e.w;
	int u = e.t;
	for (int i = 0; i < G[u].size(); ++i)
	{
		if (G[u][i].t == s) continue;
		H[s][u] = max(H[s][u], height(u, i)+e.w);
	}
	return H[s][u];
}



int main(int argc, char const *argv[])
{
	int s, t, w;
	cin >> n;
	for (int i = 0; i < n-1; ++i)
	{
		cin >> s >> t >> w;
		G[s].push_back((Edge){t, w});
		G[t].push_back((Edge){s, w});
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < G[i].size(); ++j) H[i][G[i][j].t] = -1;
	}

    for (int i = 0; i < n; ++i)
    {
    	for (int j = 0; j < G[i].size(); ++j)
    	{
    		Edge e = G[i][j];
    		if (H[i][e.t] < 0) H[i][e.t] = height(i, j);
    	}
    }

    for (int i = 0; i < n; ++i)
    {
    	for (int j = 0; j < G[i].size(); ++j) h[i] = max(h[i], H[i][G[i][j].t]);
    }

	for (int i = 0; i < n; ++i) cout << h[i] << endl;
	return 0;
}


Compiler output:
/tmp/cccLAK0O.o: in function `main':
a.cc:(.text+0x207): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cccLAK0O.o
a.cc:(.text+0x2d9): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cccLAK0O.o
a.cc:(.text+0x398): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cccLAK0O.o
a.cc:(.text+0x496): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cccLAK0O.o
a.cc:(.text+0x51e): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/cccLAK0O.o
a.cc:(.text+0x543): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/cccLAK0O.o
a.cc:(.text+0x58d): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cccLAK0O.o
a.cc:(.text+0x5b3): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/cccLAK0O.o
a.cc:(.text+0x5e3): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/cccLAK0O.o
collect2: error: ld returned 1 exit status
Language: C++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

static const int MAX_N = 1e4 + 10;

class Edge{
public:
	int t, w;
	Edge(){}
	Edge(int t, int w): t(t), w(w) {}
};

vector<Edge> G[MAX_N];
int H[MAX_N][MAX_N];
int n, h[MAX_N];

int height(int s, int idx){
	Edge e = G[s][idx];
	if (H[s][e.t]>=0) return H[s][e.t];
	H[s][e.t] = e.w;
	int u = e.t;
	for (int i = 0; i < G[u].size(); ++i)
	{
		if (G[u][i].t == s) continue;
		H[s][u] = max(H[s][u], height(u, i)+e.w);
	}
	return H[s][u];
}



int main(int argc, char const *argv[])
{
	int s, t, w;
	cin >> n;
	for (int i = 0; i < n-1; ++i)
	{
		cin >> si >> ti >> wi;
		G[si].push_back(Edge(ti, wi));
		G[ti].push_back(Edge(si, wi));
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < G[i].size(); ++j) H[i][G[i][j].t] = -1;
	}

    for (int i = 0; i < n; ++i)
    {
    	for (int j = 0; j < G[i].size(); ++j)
    	{
    		Edge e = G[i][j];
    		if (H[i][e.t] < 0) H[i][e.t] = height(i, j);
    	}
    }

    for (int i = 0; i < n; ++i)
    {
    	for (int j = 0; j < G[i].size(); ++j) h[i] = max(h[i], H[i][G[i][j].t]);
    }

	for (int i = 0; i < n; ++i) cout << h[i] << endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:41:24: error: 'si' was not declared in this scope; did you mean 'i'?
   41 |                 cin >> si >> ti >> wi;
      |                        ^~
      |                        i
a.cc:41:30: error: 'ti' was not declared in this scope; did you mean 'i'?
   41 |                 cin >> si >> ti >> wi;
      |                              ^~
      |                              i
a.cc:41:36: error: 'wi' was not declared in this scope; did you mean 'i'?
   41 |                 cin >> si >> ti >> wi;
      |                                    ^~
      |                                    i
Language: C++

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#ifdef _MSC_VER
int getchar_unlocked() { return getchar(); }
#endif
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << endl;
#define qp(f) [](auto i){return f;}
using LL=long long;
using VI=vector<int>;
using VL=vector<LL>;
using VS=vector<string>;
using VVI=vector<vector<int>>;
using PII=pair<int, int>;
const int inf = (int)1e9;
const LL MOD = 1000000007;
const double pi = acos(-1.0);
const string Snum = "0123456789";
const int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
template<class T>T Sort(T& a) { sort(a.begin(), a.end()); return a; }
template<class T>T ReSort(T& a) { sort(a.rbegin(), a.rend()); return a; }
template<class T>T Reverse(T& a) { reverse(a.begin(), a.end()); return a; }
template<class T>void Unique(T& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template<class T>auto Max(T a) { return *max_element(a.begin(), a.end()); }
template<class T>auto Min(T a) { return *min_element(a.begin(), a.end()); }
template<class T, class U>int Count(T a, U c) { return count(a.begin(), a.end(), c); }
template<class T, class U>U Sum(T a, U init = 0) { return accumulate(a.begin(), a.end(), init); }
template<class T>T Age(T a, T b) { return (a + b - 1) / b; }
template<class T>T gcd(T n, T m) { return m == 0 ? n : gcd(m, n % m); }
template<class T>T lcm(T n, T m) { return n / gcd(n, m) * m; }


struct edge {
	int to, cost;
};

int n;
vector<vector<edge>> g;

void dfs(int v, int p, int deep, VI& dist) {
	dist[v] = deep;
	for (auto e : g[v]) {
		if (e.to == p)continue;
		dfs(e.to, v, deep + e.cost, dist);
	}
}


int main() {
	scanf("%d", &n);
	g.resize(n);

	rep(i, n - 1) {
		scanf("%d%d%d", &s, &t, &w);
		g[s].pb({ t,w });
		g[t].pb({ s,w });
	}

	rep(i, n) {
		VI d(n);
		dfs(i, -1, 0, d);
		printf("%d\n", Max(d));
	}
}


Compiler output:
a.cc: In function 'int main()':
a.cc:60:34: error: 's' was not declared in this scope
   60 |                 scanf("%d%d%d", &s, &t, &w);
      |                                  ^
a.cc:60:38: error: 't' was not declared in this scope
   60 |                 scanf("%d%d%d", &s, &t, &w);
      |                                      ^
a.cc:60:42: error: 'w' was not declared in this scope
   60 |                 scanf("%d%d%d", &s, &t, &w);
      |                                          ^
Language: C++

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
//by NeighThorn
using namespace std;
const int maxn=10000+5;
int n,hd[maxn],to[maxn*2],nxt[maxn*2],w[maxn*2],cnt,maxdis[maxn],secdis[maxn];
inline void add(int s,int x,int y){
    w[cnt]=s;to[cnt]=y;nxt[cnt]=hd[x];hd[x]=cnt++;
}
inline void dfs(int root,int fa){
    for(int i=hd[root];i!=-1;i=nxt[i])
        
            dfs(to[i],root);
            if(maxdis[to[i]]+w[i]>maxdis[root])
                secdis[root]=maxdis[root],maxdis[root]=maxdis[to[i]]+w[i];
            else if(maxdis[to[i]]+w[i]>secdis[root])
                secdis[root]=maxdis[to[i]]+w[i];
        
}
inline void change(int root,int fa){
    for(int i=hd[root];i!=-1;i=nxt[i])
        
            if(maxdis[root]==maxdis[to[i]]+w[i]){
                if(maxdis[to[i]]<secdis[root]+w[i])
                    secdis[to[i]]=maxdis[to[i]],maxdis[to[i]]=secdis[root]+w[i];
                else if(secdis[to[i]]<secdis[root]+w[i])
                    secdis[to[i]]=secdis[root]+w[i];
            }
            else{
                if(maxdis[to[i]]<maxdis[root]+w[i])
                    secdis[to[i]]=maxdis[to[i]],maxdis[to[i]]=maxdis[root]+w[i];
                else if(secdis[root]<secdis[root]+w[i])
                    secdis[to[i]]=maxdis[root]+w[i];
            }
            change(to[i],root);
        
}
signed main(void){
    scanf("%d",&n);cnt=0;memset(hd,-1,sizeof(hd));
    for(int i=1,s,x,y;i<n;i++)
        scanf("%d%d%d",&x,&y,&s),add(s,x,y),add(s,y,x);
    memset(maxdis,0,sizeof(maxdis));memset(secdis,0,sizeof(secdis));
    dfs(0,-1);change(0,-1);
    for(int i=0;i<n;i++)
        printf("%d\n",maxdis[i]);
    return 0;   
}


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:16:26: error: 'i' was not declared in this scope
   16 |             if(maxdis[to[i]]+w[i]>maxdis[root])
      |                          ^
a.cc: In function 'void change(int, int)':
a.cc:37:23: error: 'i' was not declared in this scope
   37 |             change(to[i],root);
      |                       ^
Language: C++

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

#define rep(i,n) for(ll i=0;i<n;i++)
#define ALL(a) a.begin(),a.end()
#define pb push_back

ll n;
vector<vector<P>> g;
map<P,ll> dp;

ll dfs(ll p, ll par) {
	if(dp.count(P(p,par))) return dp[P(p,par)];
	ll ret=0;
	rep(i,(ll)g[p].size()) {
		if(g[p][i].first==par) continue;
		ret=max(ret,dfs(g[p][i].first,p)+g[p][i].second);
	}
	return dp[P(p,par)]=ret;
}

int main() {
	cin>>n;
	if(n>=8000) return
	g.assign(n,vector<P>(0));
	rep(i,n-1) {
		ll s,t,w;
		cin>>s>>t>>w;
		g[s].pb(P(t,w));
		g[t].pb(P(s,w));
	}
	vector<ll> ans(n,0);
	rep(i,n) {
		rep(j,(ll)g[i].size()) {
			ans[i]=max(ans[i],dfs(g[i][j].first,i)+g[i][j].second);
		}
	}
	rep(i,n) cout<<ans[i]<<endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:28:17: error: void value not ignored as it ought to be
   28 |         g.assign(n,vector<P>(0));
      |         ~~~~~~~~^~~~~~~~~~~~~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

#define rep(i,n) for(ll i=0;i<n;i++)
#define ALL(a) a.begin(),a.end()
#define pb push_back

ll n;
vector<vector<P>> g;
map<P,ll> dp;

ll dfs(ll p, ll par) {
	if(dp.count(P(p,par))) return dp[P(p,par)];
	ll ret=0;
	rep(i,(ll)g[p].size()) {
		if(g[p][i].first==par) continue;
		ret=max(ret,dfs(g[p][i].first,p)+g[p][i].second);
	}
	return dp[P(p,par)]=ret;
}

int main() {
	cin>>n;
	if(n>=8000) return;
	g.assign(n,vector<P>(0));
	rep(i,n-1) {
		ll s,t,w;
		cin>>s>>t>>w;
		g[s].pb(P(t,w));
		g[t].pb(P(s,w));
	}
	vector<ll> ans(n,0);
	rep(i,n) {
		rep(j,(ll)g[i].size()) {
			ans[i]=max(ans[i],dfs(g[i][j].first,i)+g[i][j].second);
		}
	}
	rep(i,n) cout<<ans[i]<<endl;
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:27:21: error: return-statement with no value, in function returning 'int' [-fpermissive]
   27 |         if(n>=8000) return;
      |                     ^~~~~~
Language: C++

#include<bits/stdc++.h>
#define si(i) scanf("%d", &i)
#define sll(i) scanf("%lld", &i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl '\n'
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef pair< int, int > pii;

int n, l[100005];
int f[100005][17];
vector< vector<int> >v;

int main(){
    memset( f[0], -1, sizeof f[0]);
    si(n);
    v.resize(n);
    int nn = 32 - __builtin_clz(n);
    for( int i = 0 ; i < n ; i++ ){
        int k; si(k);
        for( int j = 0 ; j < k ; j++ ){
            int c; si(c);
            v[i].pb(c);
            f[0][c] = i;
        }
    }
    queue < int >q;
    l[0] = 0;
    q.push(0);
    while( q.size() ){
        int x = q.front();
        q.pop();
        for( int i = 0 ; i < v[x].size() ; i++ ){
            l[v[x][i]] = l[x] + 1;
            q.push(mp( l[x] + 1, v[x][i]));
        }
    }
    
    for( int i = 1 ; i <= nn ; i++ ){
        for( int j = 0 ; j < n ; j++ ){
            int x = f[i - 1][j];
            if( x == -1 ){
                f[i][j] = -1;
                continue;
            }
            int y = f[i - 1][x];
            f[i][j] = y;
        }
    }
    int _q; si(_q);
    while( _q-- ){
        int u, v;
        si(u); si(v);
        if( l[u] < l[v] ) swap( u, v );
        for( int i = nn ; i >= 0 ; i-- ){
            if( ( 1 << i ) <= l[u] - l[v] ){
                u = f[i][u];
            }
        }
        if( u == v ){
            cout << u << nl;
            continue;
        }
        for( int i = nn ; i >= 0 ; i-- ){
            if( f[i][u] == f[i][v] ) continue;
            u = f[i][u];
            v = f[i][v];
        }
        cout << f[0][u] << nl;
    }
    
}



Compiler output:
a.cc: In function 'int main()':
a.cc:39:19: error: no matching function for call to 'std::queue<int>::push(std::pair<int, int>)'
   39 |             q.push(mp( l[x] + 1, v[x][i]));
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:157,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_queue.h:283:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = int; _Sequence = std::deque<int, std::allocator<int> >; value_type = int]'
  283 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:283:30: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'const std::queue<int>::value_type&' {aka 'const int&'}
  283 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:288:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(value_type&&) [with _Tp = int; _Sequence = std::deque<int, std::allocator<int> >; value_type = int]'
  288 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:288:25: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::queue<int>::value_type&&' {aka 'int&&'}
  288 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <string.h>
#include <algorithm>
#define P pair<int,int>
#define INF (1 << 30)
using namespace std;

vector<int> index(100010);  
vector<bool> f(100010, false);
vector<vector<int>> T(100010); //??°??????
vector<P> ET;              //??????????????¨

//??°???????????????????????¨????????????index?????¨??????????´??????????????????¨?????????????????????????????????????????????
//ET : 2n - 1 ?????????????????¨??? (??±??????????´???????????????????
void dfs(int n,int dep) {
	f[n] = true;
	ET.emplace_back(make_pair(dep,n));
	index[n] = ET.size() - 1;
	for (int next : T[n]) {
		if (f[next] == true) continue;
		dfs(next,dep + 1);
		ET.emplace_back(make_pair(dep,n));
	}
}

P RMQ(int a, int b, int k, int l, int r,vector<P>& node) {
	if (r <= a || b <= l)return make_pair(INF, 0);
	if (a <= l && r <= b) { return node[k]; }
	P vl = RMQ(a, b, 2 * k + 1, l, (l + r) / 2,node);
	P vr = RMQ(a, b, 2 * k + 2, (l + r) / 2, r,node);

	if (vl.first > vr.first) {
		return vr;
	}
	else { return vl; }
}


int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n_; cin >> n_;
	vector<int> v(n_);
	for (int i = 0; i < n_; i++) {
		int k; cin >> k;
		for (int j = 0; j < k; j++) {
			int c; cin >> c;
			T[i].emplace_back(c);
			T[c].emplace_back(i);
		}
	}

Compiler output:
a.cc:10:18: error: 'std::vector<int> index' redeclared as different kind of entity
   10 | vector<int> index(100010);
      |                  ^
In file included from /usr/include/string.h:462,
                 from a.cc:4:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'void dfs(int, int)':
a.cc:20:14: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   20 |         index[n] = ET.size() - 1;
      |              ^
a.cc: In function 'int main()':
a.cc:52:10: error: expected '}' at end of input
   52 |         }
      |          ^
a.cc:41:12: note: to match this '{'
   41 | int main() {
      |            ^
Language: C++

#include <iostream>
#include <vector>
#include <map>
#include <string.h>
#include <algorithm>
#define P pair<int,int>
#define INF (1 << 30)
using namespace std;

vector<int> index(100010);  
vector<bool> f(100010, false);
vector<vector<int>> T(100010); //??°??????
vector<P> ET;              //??????????????¨

//??°???????????????????????¨????????????index?????¨??????????´??????????????????¨?????????????????????????????????????????????
//ET : 2n - 1 ?????????????????¨??? (??±??????????´???????????????????
void dfs(int n,int dep) {
	f[n] = true;
	ET.emplace_back(make_pair(dep,n));
	index[n] = ET.size() - 1;
	for (int next : T[n]) {
		if (f[next] == true) continue;
		dfs(next,dep + 1);
		ET.emplace_back(make_pair(dep,n));
	}
}

P RMQ(int a, int b, int k, int l, int r,vector<P>& node) {
	if (r <= a || b <= l)return make_pair(INF, 0);
	if (a <= l && r <= b) { return node[k]; }
	P vl = RMQ(a, b, 2 * k + 1, l, (l + r) / 2,node);
	P vr = RMQ(a, b, 2 * k + 2, (l + r) / 2, r,node);

	if (vl.first > vr.first) {
		return vr;
	}
	else { return vl; }
}


int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n_; cin >> n_;
	vector<int> v(n_);
	for (int i = 0; i < n_; i++) {
		int k; cin >> k;
		for (int j = 0; j < k; j++) {
			int c; cin >> c;
			T[i].emplace_back(c);
			T[c].emplace_back(i);
		}
	}

	dfs(0,0);

	n_ = ET.size();
	int n = 1;
	while (n < n_) n *= 2;
	vector<P> node(2 * n - 1,make_pair(INF,0));
	for (int i = 0; i < n_;i++) {
		node[n - 1 + i] = ET[i];
	}	
	for (int i = n - 2; i >= 0; i--) {
		if (node[2 * i + 1].first > node[2 * i + 2].first) {
			node[i] = node[2 * i + 2];
		}
		else { 
			node[i] = node[2 * i + 1];
		}
	}
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int u, v; cin >> u >> v;
		int a = index[u], b = index[v];
		if (a > b) swap(a, b);
		cout << RMQ(a, b, 0, 0, n_, node).second << endl;
	}
}

Compiler output:
a.cc:10:18: error: 'std::vector<int> index' redeclared as different kind of entity
   10 | vector<int> index(100010);
      |                  ^
In file included from /usr/include/string.h:462,
                 from a.cc:4:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'void dfs(int, int)':
a.cc:20:14: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   20 |         index[n] = ET.size() - 1;
      |              ^
a.cc: In function 'int main()':
a.cc:74:30: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   74 |                 int a = index[u], b = index[v];
      |                              ^
a.cc:75:25: error: 'b' was not declared in this scope
   75 |                 if (a > b) swap(a, b);
      |                         ^
a.cc:76:32: error: 'b' was not declared in this scope
   76 |                 cout << RMQ(a, b, 0, 0, n_, node).second << endl;
      |                                ^
Language: C++

//lca
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}

/*
lca(u,v)????????¨???O(logN)??§?±???????
?????????O(NlogN)
p??¨depth???????????£????????°????????????genlca????????§????????????,?????¬?????°??????G???????????¶????????¨
??????dfs+genlca??????????????????

path???????§£????????¨??????[u,z) + [v,z) + z ?????????????????????, ???????????????????????????(depth-1???????????????)??¨ok

*/

int bsr(uint x){	//4~7 -> 2
	if(x==0) return -1;
	return 31 ^ __builtin_clz(x);
}
struct LCA{
	int N,n;
	vector<int> depth;
	vector<vector<int>> par;

	void dfs(int v,int p,vector<vector<int>>& G){
		if(p<0) depth[v]=0;
		else depth[v]=depth[p]+1;
		par[v][0]=p;
		for(int u:G[v]){
			if(u!=p) dfs(u,v,G);
		}
	}

	LCA(const vector<vector<int>>& G){
		N = G.size();
		n = bsr(N);
		depth = vector<int>(N,0);
		par = vector<vector<int>>(N,vector<int>(n+1,0));

		dfs(0,-1,G);
		rep1(i,n){
			rep(v,N){
				if(par[v][i-1]==-1){
					par[v][i]=-1;
				}else{
					par[v][i]=par[par[v][i-1]][i-1];
				}
			}
		}
	}

	int lca(int u,int v){
		if(depth[u]<depth[v]){
			swap(u,v);
		}
		int d=depth[u]-depth[v];
		rep(i,n+1){
			if((d>>i)&1) u=par[u][i];
		}
		if(u==v) return u;
		for(int i=n;i>=0;i--){
			if(par[u][i]!=par[v][i]){
				u=par[u][i];
				v=par[v][i];
			}
		}
		return par[v][0];
	}

	int distance(int u,int v){
		return depth[u] + depth[v] - 2*depth[lca(u,v)];
	}
};


int main(){
	int N,Q;
	cin>>N;
	vector<vector<int>> G(N);
	rep(i,N){
		int n;
		cin>>n;
		rep(j,n){
			int x;
			cin>>x;
			G[i].pb(x);
			G[x].pb(i);
		}
	}
	LCA lca(G);
	cin>>Q;
	rep(q,Q){
		int x,y;
		cin>>x>>y;
		cout<<lca.lca(x,y)<<endl;
	}
}

Compiler output:
a.cc: In constructor 'LCA::LCA(const std::vector<std::vector<int> >&)':
a.cc:50:26: error: binding reference of type 'std::vector<std::vector<int> >&' to 'const std::vector<std::vector<int> >' discards qualifiers
   50 |                 dfs(0,-1,G);
      |                          ^
a.cc:35:51: note:   initializing argument 3 of 'void LCA::dfs(int, int, std::vector<std::vector<int> >&)'
   35 |         void dfs(int v,int p,vector<vector<int>>& G){
      |                              ~~~~~~~~~~~~~~~~~~~~~^
Language: C++

#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))

#define INF 200000000

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
using pii = pair<ll, int>;

vector<int> G[100000];
vector<int> et, depth, id;

struct ST
{
	vector<pii> data;
	int n;
	int segn;

	ST(int v,int k):n(v)
	{
		for (segn = 1; segn < (n * 2 - 1); segn *= 2);
		data.assign(2 * segn, make_pair(INF, -1));
		for (int i = 0; i < k; i++)
		{
			data[segn + i] = make_pair(depth[i], et[i]);
		}
		for (int i = segn - 1; i >= 1; --i)
		{
			data[i] = min(data[i * 2], data[i * 2 + 1]);
		}
	}

	pii find(int s, int t, int l, int r)
	{
		if (r == -1)
		{
			r = segn;
		}
		if (t <= s || r == 0)
		{
			return make_pair(INF, -1);
		}
		if (t - s == r)
		{
			return data[l];
		}

		return min(find(s, min(t, r / 2), l * 2, r / 2), find(max(0, s - (r / 2)), t - (r / 2), l * 2 + 1, r / 2));
	}
};

void ET(int n, int p, int& eti, int d)
{
	id[n] = eti;
	et[eti] = n;
	depth[eti] = d;
	eti++;

	for (auto& e : G[n])
	{
		if (e != p)
		{
			ET(e, n, eti, d + 1);
			et[eti] = n;
			depth[eti] = d;
			eti++;
		}
	}
}

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

	int n;
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int k;
		cin >> k;

		for (int j = 0; j < k; j++)
		{
			int c;
			cin >> c;
			G[i].emplace_back(c);
		}
	}

	et = vector<int>(n * 2 - 1);
	depth = vector<int>(n * 2 - 1);
	id = vector<int>(n);

	int eti = 0;
	ET(0, -1, eti, 0);

	ST st(n,eti);

	int q;
	cin >> q;

	for (int i = 0; i < q; i++)
	{
		int u, v;
		cin >> u >> v;

		printf("%d\n", st.find(min(id[u], id[v]), max(id[u], id[v]) + 1, 1, -1).second);
	}

	return 0;
}


Compiler output:
a.cc:31:7: error: conflicting declaration 'using pii = struct std::pair<long long int, int>'
   31 | using pii = pair<ll, int>;
      |       ^~~
a.cc:29:24: note: previous declaration as 'typedef struct std::pair<int, int> pii'
   29 | typedef pair<int, int> pii;
      |                        ^~~
Language: C++

#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;
template <typename Functor>
struct fix_type
{
    Functor functor;
    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); }
};
template <typename Functor>
fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; }



struct Graph
{
    Graph(const int v)
        : V{v}, edge(v), rev_edge(v) {}
    void addEdge(const int from, const int to)
    {
        edge[from].push_back(to);
        rev_edge[to].push_back(from);
    }
    const int V;
    vector<vector<int>> edge;
    vector<vector<int>> rev_edge;
};



class LowestCommonAncestor
{
public:
    LowestCommonAncestor(const Graph& g, const int root = 0) : left(g.V, 0)
    {
        vector<bool> used(g.V, false);
        dfs(g, make_pair(0, root), used);
    }  // 無向根付き木
    int LCA(const int u, const int v) const
    {
        static const SparseTable<DepthMin> st{depth};
        const int ul = left[u];
        const int vl = left[v];
        return st.accumulate(min(ul, vl), max(ul, vl) + 1).second;
    }

private:
    struct DepthMin
    {
        using T = pair<int, int>;
        T operator()(const T& a, const T& b) const { return min(a, b); }
    };

    void dfs(const Graph& g, const pair<int, int> s, vector<bool>& used)
    {
        used[s.second] = true;
        const int pos = s.second;
        left[pos] = depth.size();
        depth.push_back(s);
        for (const int to : g.edge[pos]) {
            if (used[to]) continue;
            dfs(g, make_pair(s.first + 1, to), used);
            depth.push_back(s);
        }
    }
    vector<int> left;
    vector<pair<int, int>> depth;
};



// Problem: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_C
// Status: Accepted

int main()
{
    int n;
    cin >> n;
    Graph g(n);
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int c;
            cin >> c;
            g.addEdge(i, c);
        }
    }

    LowestCommonAncestor lca{g};
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int u, v;
        cin >> u >> v;
        cout << lca.LCA(u, v) << endl;
    }
    return 0;
}



Compiler output:
a.cc: In member function 'int LowestCommonAncestor::LCA(int, int) const':
a.cc:47:22: error: 'SparseTable' does not name a type
   47 |         static const SparseTable<DepthMin> st{depth};
      |                      ^~~~~~~~~~~
a.cc:50:16: error: 'st' was not declared in this scope; did you mean 'std'?
   50 |         return st.accumulate(min(ul, vl), max(ul, vl) + 1).second;
      |                ^~
      |                std
Language: C++


#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;
template <typename Functor>
struct fix_type
{
    Functor functor;
    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); }
};
template <typename Functor>
fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; }



struct Graph
{
    Graph(const int v) : V{v}, edge(v), rev_edge(v) {}
    void addEdge(const int from, const int to)
    {
        edge[from].push_back(to);
        rev_edge[to].push_back(from);
    }
    const int V;
    vector<vector<int>> edge;
    vector<vector<int>> rev_edge;
};



class LowestCommonAncestor
{
public:
    LowestCommonAncestor(const Graph& g, const int root = 0) : left(g.V, 0)  // 無向根付き木
    {
        vector<bool> used(g.V, false);
        auto dfs = fix([&](auto&& self, const pair<int, int>& s) -> void {
            used[s.second] = true;
            const int pos = s.second;
            left[pos] = depth.size();
            depth.push_back(s);
            for (const int to : g.edge[pos]) {
                if (used[to]) { continue; }
                self(self, {s.first + 1, to});
                depth.push_back(s);
            }
        });
        dfs(make_pair(0, root));
    }
    int LCA(const int u, const int v) const
    {
        static const SparseTable<DepthMin> st{depth};
        const int ul = left[u];
        const int vl = left[v];
        return st.accumulate(min(ul, vl), max(ul, vl) + 1).second;
    }

private:
    struct DepthMin
    {
        using T = pair<int, int>;
        T operator()(const T& a, const T& b) const { return min(a, b); }
    };
    vector<int> left;
    vector<pair<int, int>> depth;
};



// Problem: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_C
// Status: Accepted

int main()
{
    int n;
    cin >> n;
    Graph g(n);
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int c;
            cin >> c;
            g.addEdge(i, c);
        }
    }

    LowestCommonAncestor lca{g};
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int u, v;
        cin >> u >> v;
        cout << lca.LCA(u, v) << endl;
    }
    return 0;
}



Compiler output:
a.cc: In member function 'int LowestCommonAncestor::LCA(int, int) const':
a.cc:58:22: error: 'SparseTable' does not name a type
   58 |         static const SparseTable<DepthMin> st{depth};
      |                      ^~~~~~~~~~~
a.cc:61:16: error: 'st' was not declared in this scope; did you mean 'std'?
   61 |         return st.accumulate(min(ul, vl), max(ul, vl) + 1).second;
      |                ^~
      |                std
Language: C++

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


class RMQ{//RangeMinimumQuery
	int n;
	std::vector<int> dat,idx;
	static int calcsize(int n){
		int res=1;
		while(res<n)res<<=1;
		return res;
	}
	int query(int a,int b,int k,int l,int r)const{
		if(r<=a||b<=l)return dat.size()-1;
		if(a<=l&&r<=b)return idx[k];
		else{
			int vl=query(a,b,k*2+1,l,(l+r)/2);
			int vr=query(a,b,k*2+2,(l+r)/2,r);
			return dat[vl]<dat[vr]?vl:vr;
		}
	}
public:
	RMQ(){}
	~RMQ(){}
	void build(const std::vector<int> &a){
		n=calcsize(a.size());
		idx.resize(2*n-1);
		for(int i=0;i<(int)a.size();i++)idx[n-1+i]=i;
		for(int i=a.size();i<n;i++)idx[n-1+i]=a.size();
		dat=a;
		dat.push_back(INT_MAX);
		for(int i=n-2;i>=0;i--){
			idx[i]=dat[idx[i*2+1]]<dat[idx[i*2+2]]?idx[i*2+1]:idx[i*2+2];
		}
	}
	int query(int a,int b)const{//[a,b)の最小値
		return query(a,b,0,0,n);
	}
};


class LCA{
	vector<pair<int,int> > eulertour;
	vector<int> vertex;
	RMQ rmq;
	void dfs(const vector<int> edge[],int n,vector<int> &depth,int d,int u){
		eulertour[u].first=vertex.size();	
		vertex.push_back(u);
		depth.push_back(d);
		for(int i=0;i<edge[u].size();i++){
			dfs(edge,n,depth,d+1,edge[u][i]);
			eulertour[u].second=vertex.size();
			vertex.push_back(u);
			depth.push_back(d);
		}
		if(edge[u].empty()){
			eulertour[u].second=vertex.size();
			vertex.push_back(u);
			depth.push_back(d);
		}
	}
public:
	LCA(const vector<int> edge[],int n,int root):eulertour(n){
		vector<int> depth;
		dfs(edge,n,depth,0,root);
		rmq.build(depth);
	}
	int query(int u,int v)const{
		if(u==v)return u;
		if(eulertour[u].first<eulertour[v].first && eulertour[v].second<eulertour[u].second)
			return u;
		if(eulertour[v].first<eulertour[u].first && eulertour[u].second<eulertour[v].second)
			return v;
		if(eulertour[u].first>eulertour[v].first)swap(u,v);
		return vertex[rmq.query(eulertour[u].second, eulertour[v].first)];
	}
};


vector<int> edge[100000];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int k,v;
		cin>>k;
		for(int j=0;j<k;j++){
			cin>>v;
			edge[i].push_back(v);
		}
	}
	LCA lca(edge,n,0);
	int q,u,v;
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>u>>v;
		cout<<lca.query(u,v)<<endl;
	}
	return 0;
}

Compiler output:
a.cc: In member function 'void RMQ::build(const std::vector<int>&)':
a.cc:34:31: error: 'INT_MAX' was not declared in this scope
   34 |                 dat.push_back(INT_MAX);
      |                               ^~~~~~~
a.cc:5:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    4 | #include<utility>
  +++ |+#include <climits>
    5 | using namespace std;