Language: C++

#include <bits/stdc++.h>
#define int ll
#define N 210010
#define ls c[rt][0]
#define rs c[rt][1]
#define lw w[rt][0]
#define rw w[rt][1]
using namespace std;
typedef long long ll;
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct node{ll x,y;};
int n,c[N][2],w[N][2],tmp1,tmp2;
vector <node> V[N];
node tt1[N],tt2[N];

inline void Insert(int x,node d)
{
	int i=V[x].size()-1;
	if(V[x].empty()) { V[x].push_back(d); return ;}
	if(V[x][i].y<=d.y) return ;
	while(i>=0&&V[x][i].x>=d.x) i--,V[x].pop_back();
	V[x].push_back(d);
}
bool check(int rt,ll tar)
{
	V[rt].clear();
	if(!ls){Insert(rt,(node){0,0}); return 1;}
	int ck=check(ls,tar)|check(rs,tar);
	if(!ck) return ck; 	tmp1=0; tmp2=0; 
	int ll=V[ls].size()-1,rr=V[rs].size()-1;
	for(int i=ll,j=rr;i>=0;i--)
	{
		while(j>=0&&V[ls][i].x+V[rs][j].y+lw+rw>tar) j--;
		if(j>=0) tt1[++tmp1]=(node){V[ls][i].x+lw,V[rs][j].y+rw};
	}
	for(int i=rr,j=ll;i>=0;i--)
	{
		while(j>=0&&V[rs][i].x+V[ls][j].y+lw+rw>tar) j--;
		if(j>=0) tt2[++tmp2]=(node){V[rs][i].x+rw,V[ls][j].y+lw};
	}
	for(int i=1,j=tmp1;i<=j;i++,j--) swap(tt1[i],tt1[j]);
	for(int i=1,j=tmp2;i<=j;i++,j--) swap(tt2[i],tt2[j]);
	int i=1,j=1; while(i<=tmp1&&j<=tmp2)
	{
		if(tt1[i].x<tt2[j].x) Insert(rt,tt1[i]),i++;
		else Insert(rt,tt2[j]),j++;
	} while(i<=tmp1) Insert(rt,tt1[i]),i++;
	  while(j<=tmp2) Insert(rt,tt2[j]),j++;
	  return !V[rt].empty();
}
signed main()
{
	//freopen("read.in","r",stdin);
	n=read(); for(int i=2;i<=n;i++)
	{
		int rt=read(),y=read();
		if(!ls) ls=i,lw=y; else rs=i,rw=y;
	}
	ll l=0, r=1000000000000ll, ans=0;
	while(l<=r)
	{
		ll mid=(l+r)>>1;// mid=14;
		if(check(1,mid)) ans=mid,r=mid-1;
		else l=mid+1;
	}cout << ans << endl; return 0;
}

Compiler output:
a.cc: In function 'bool check(ll, ll)':
a.cc:37:17: error: expected ';' before 'i'
   37 |         for(int i=ll,j=rr;i>=0;i--)
      |                 ^
a.cc:37:27: error: 'i' was not declared in this scope
   37 |         for(int i=ll,j=rr;i>=0;i--)
      |                           ^
a.cc:39:23: error: 'j' was not declared in this scope
   39 |                 while(j>=0&&V[ls][i].x+V[rs][j].y+lw+rw>tar) j--;
      |                       ^
a.cc:40:20: error: 'j' was not declared in this scope
   40 |                 if(j>=0) tt1[++tmp1]=(node){V[ls][i].x+lw,V[rs][j].y+rw};
      |                    ^
a.cc:42:17: error: expected ';' before 'i'
   42 |         for(int i=rr,j=ll;i>=0;i--)
      |                 ^
a.cc:42:27: error: 'i' was not declared in this scope
   42 |         for(int i=rr,j=ll;i>=0;i--)
      |                           ^
a.cc:44:23: error: 'j' was not declared in this scope
   44 |                 while(j>=0&&V[rs][i].x+V[ls][j].y+lw+rw>tar) j--;
      |                       ^
a.cc:45:20: error: 'j' was not declared in this scope
   45 |                 if(j>=0) tt2[++tmp2]=(node){V[rs][i].x+rw,V[ls][j].y+lw};
      |                    ^
a.cc:47:17: error: expected ';' before 'i'
   47 |         for(int i=1,j=tmp1;i<=j;i++,j--) swap(tt1[i],tt1[j]);
      |                 ^
a.cc:47:28: error: 'i' was not declared in this scope
   47 |         for(int i=1,j=tmp1;i<=j;i++,j--) swap(tt1[i],tt1[j]);
      |                            ^
a.cc:47:31: error: 'j' was not declared in this scope
   47 |         for(int i=1,j=tmp1;i<=j;i++,j--) swap(tt1[i],tt1[j]);
      |                               ^
a.cc:48:17: error: expected ';' before 'i'
   48 |         for(int i=1,j=tmp2;i<=j;i++,j--) swap(tt2[i],tt2[j]);
      |                 ^
a.cc:48:28: error: 'i' was not declared in this scope
   48 |         for(int i=1,j=tmp2;i<=j;i++,j--) swap(tt2[i],tt2[j]);
      |                            ^
a.cc:48:31: error: 'j' was not declared in this scope
   48 |         for(int i=1,j=tmp2;i<=j;i++,j--) swap(tt2[i],tt2[j]);
      |                               ^
a.cc:49:13: error: expected ';' before 'i'
   49 |         int i=1,j=1; while(i<=tmp1&&j<=tmp2)
      |             ^
a.cc:49:28: error: 'i' was not declared in this scope
   49 |         int i=1,j=1; while(i<=tmp1&&j<=tmp2)
      |                            ^
a.cc:49:37: error: 'j' was not declared in this scope
   49 |         int i=1,j=1; while(i<=tmp1&&j<=tmp2)
      |                                     ^
a.cc:53:17: error: 'i' was not declared in this scope
   53 |         } while(i<=tmp1) Insert(rt,tt1[i]),i++;
      |                 ^
a.cc:54:17: error: 'j' was not declared in this scope
   54 |           while(j<=tmp2) Insert(rt,tt2[j]),j++;
      |                 ^