Language: C++

//?????????????????¢?????§???2??????????????????????????????????????????O(logN)
//LCA??§???2????????????????????????O(logN)
//2??????????????¨?????????????????¶????????????????????¢?????§?????????3??????????????§???3????????????????????°???????????????
//??§???N = 2?????¨????????????????????????????????????????????????????????????????????????????????????????????????

#include <iostream>
using namespace std;

int n;
vector<int> et[100000], ec[100000];
int maxi[100000];	//maxi[i] = ??????i??\??????????????????????????????????????§?????????
int isLeaf[100000];	//isLeaf[i] = ??????i????????§?????????
int dist[100000];	//dist[i] = ??????i?????????0????????????????????¢???????????????(????????????)
int parents[20][100000];	//parents[i][j] = ??????j???(1<<i)????????????
int distNc[100000];	//distNc[i] = dist[i]????????????????????????????????§???

//maxi[v]?????????
int dfs(int parent, int v, int cst, int cstNc){
	int i;
	
	dist[v] = cst;
	distNc[v] = cstNc;
	parents[0][v] = parent;
	for( i = 0; i < et[v].size(); i++ ){
		if( parent == et[v][i] ) continue;
		break;
	}
	if( i == et[v].size() ){ isLeaf[v] = 1; return 0; }
	//?????§???????????¨???
	int ret = 0;
	for( i = 0; i < et[v].size(); i++ ){
		if( parent == et[v][i] ) continue;
		ret = max(ret, max(ec[v][i], dfs(v, et[v][i], cst + ec[v][i], cstNc + 1)));
	}
	maxi[v] = ret;
	return ret;
}

//lca????§?????????????
void prepare(){
	int i, j;
	for( i = 1; i < 20; i++ )
		for( j = 0; j < n; j++ )
			parents[i][j] = parent[i-1][parents[i][j-1]];
}

//lca????±???????
int lca(int u, int v){
	int i;
	if( distNc[u] > distNc[v] ){
		for( i = 0; distNc[u] - (1<<i) >= distNc[v]; i++ );
		i--;
		return lca(parents[i][u], v);
	}
	else if( distNc[v] > distNc[u] ){
		for( i = 0; distNc[v] - (1<<i) >= distNc[u]; i++ );
		i--;
		return lca(u, parents[i][v]);
	}
	else{
		for( i = 0; parents[i][u] != parents[i][v]; i++ );
		i--;
		i = max(i, 0);
		return lca(parents[i][u], parents[i][v]);
	}
}

//2????????????????????????????±???????
int sumCost(int u, int v){
	int lc = lca(u, v);
	return dist[u] + dist[v] - dist[lc] * 2;
}

//2???????????????????????????????????????????±???????
int maxCost(int u, int v){
}

//?????????????????¢?????§??????3????????????????????????
vector<int> most3Leaf(){
}

int main(){
	int i;
	
	cin >> n;
	for( i = 0; i < n; i++ ){
		int p, w;
		cin >> p >> w;
		et[i].push_back(p);
		et[p].push_back(i);
		ec[i].push_back(w);
		ec[p].push_back(w);
	}
	
	dfs(0, 0, 0, 0);
	return 0;
}

Compiler output:
a.cc:10:1: error: 'vector' does not name a type
   10 | vector<int> et[100000], ec[100000];
      | ^~~~~~
a.cc: In function 'int dfs(int, int, int, int)':
a.cc:24:25: error: 'et' was not declared in this scope
   24 |         for( i = 0; i < et[v].size(); i++ ){
      |                         ^~
a.cc:28:18: error: 'et' was not declared in this scope
   28 |         if( i == et[v].size() ){ isLeaf[v] = 1; return 0; }
      |                  ^~
a.cc:31:25: error: 'et' was not declared in this scope; did you mean 'ret'?
   31 |         for( i = 0; i < et[v].size(); i++ ){
      |                         ^~
      |                         ret
a.cc:33:36: error: 'ec' was not declared in this scope
   33 |                 ret = max(ret, max(ec[v][i], dfs(v, et[v][i], cst + ec[v][i], cstNc + 1)));
      |                                    ^~
a.cc: In function 'void prepare()':
a.cc:44:41: error: 'parent' was not declared in this scope; did you mean 'parents'?
   44 |                         parents[i][j] = parent[i-1][parents[i][j-1]];
      |                                         ^~~~~~
      |                                         parents
a.cc: In function 'int maxCost(int, int)':
a.cc:76:1: warning: no return statement in function returning non-void [-Wreturn-type]
   76 | }
      | ^
a.cc: At global scope:
a.cc:79:1: error: 'vector' does not name a type
   79 | vector<int> most3Leaf(){
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:89:17: error: 'et' was not declared in this scope
   89 |                 et[i].push_back(p);
      |                 ^~
a.cc:91:17: error: 'ec' was not declared in this scope
   91 |                 ec[i].push_back(w);
      |                 ^~