Language: C++

#include<cstdio>
#include<algorithm>
#include<vector>
#define maxn 131080
#define LL long long
using namespace std;
typedef pair<LL,LL> PLL;
int n,fa[maxn];
vector<PLL> f[maxn];
struct node { int v,w; node *nxt; } edge[maxn],*head[maxn],*ncnt;
void addedge(int u,int v,int w)
{
	ncnt++;
	ncnt->v=v,ncnt->w=w,ncnt->nxt=head[u];
	head[u]=ncnt;
}
/*#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<pr> vec;
#define x first
#define y second
const int N=131100;
int n,fa[N];
vec g[N],f[N];
ll mid,mv[N];
inline bool cmpx(pr a,pr b){return a.x<b.x;}
inline bool cmpy(pr a,pr b){return a.y<b.y;}
inline void work(vec &ls,vec &rs,vec &f)
{
    if(ls.size()>rs.size())swap(ls,rs);
    int el=ls.size(),er=rs.size();
    sort(ls.begin(),ls.end(),cmpy);
    sort(rs.begin(),rs.end(),cmpx);
    mv[0]=rs[0].y;
    for(int i=1;i<er;i++) mv[i]=min(mv[i-1],rs[i].y);
    for(int i=0,j=er-1;i<el;i++)
    {
        while(j>=0 && ls[i].y+rs[j].x>mid)j--;
        if(j>=0)f.push_back(pr(ls[i].x,mv[j]));
    }
    sort(ls.begin(),ls.end(),cmpx);
    sort(rs.begin(),rs.end(),cmpy);
    mv[0]=rs[0].x;
    for(int i=1;i<er;i++) mv[i]=min(mv[i-1],rs[i].x);
    for(int i=0,j=er-1;i<el;i++)
    {
        while(j>=0 && ls[i].x+rs[j].y>mid)j--;
        if(j>=0)f.push_back(pr(mv[j],ls[i].y));
    }
}
inline void dfs(int u)
{
    if(!f[u].empty())f[u].clear();
    if(g[u].empty())
    {
        f[u].push_back(pr(0,0));
        return;
    }
    for(int i=0,e=g[u].size();i<e;i++)
        dfs(g[u][i].x);
    vec &ls=f[g[u][0].x];
    for(int i=0,e=ls.size(),c=g[u][0].y;i<e;i++)
        ls[i].x+=c,ls[i].y+=c;
    vec &rs=f[g[u][1].x];
    for(int i=0,e=rs.size(),c=g[u][1].y;i<e;i++)
        rs[i].x+=c,rs[i].y+=c;
    work(ls,rs,f[u]);
    ls.clear();
    rs.clear();
}*/
void dfs(int u)
{
	f[u].clear();
	if(!head[u]) { f[u].push_back(PLL(0,0)); return; }
	for(node *p=head[u];p;p=p->nxt) dfs(p->v);
	vector<PLL> &ls=f[head[u]->v];
	for(int i=0,siz=f[head[u]->v])
}
LL BS()
{
	LL l=0,r=(LL)1e10;
	while(l+1<r)
	{
		int mid=(l+r)/2; dfs(1,mid);
		if(f[1].empty()) l=mid;
		else r=mid;
	}
	return r;
}
int main()
{
	freopen("travel.in","r",stdin);
	freopen("travel.out","w",stdout);
	ncnt=&edge[0];
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		int w;
		scanf("%d%d",&fa[i],&w);
		addedge(fa[i],i,w);
	}
	printf("%lld\n",BS());
}

Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:79:37: error: cannot convert 'std::vector<std::pair<long long int, long long int> >' to 'int' in initialization
   79 |         for(int i=0,siz=f[head[u]->v])
      |                         ~~~~~~~~~~~~^
      |                                     |
      |                                     std::vector<std::pair<long long int, long long int> >
a.cc:79:38: error: expected ';' before ')' token
   79 |         for(int i=0,siz=f[head[u]->v])
      |                                      ^
      |                                      ;
a.cc:79:38: error: expected primary-expression before ')' token
a.cc:79:38: error: expected ';' before ')' token
   79 |         for(int i=0,siz=f[head[u]->v])
      |                                      ^
      |                                      ;
a.cc:80:1: error: expected primary-expression before '}' token
   80 | }
      | ^
a.cc: In function 'long long int BS()':
a.cc:86:37: error: too many arguments to function 'void dfs(int)'
   86 |                 int mid=(l+r)/2; dfs(1,mid);
      |                                  ~~~^~~~~~~
a.cc:73:6: note: declared here
   73 | void dfs(int u)
      |      ^~~