Language: C++

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

const int RLEN=1<<18|1;
inline char nc() {
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
    char ch=nc(); int i=0,f=1;
    while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
    while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
    return i*f;
}

const int N=2e5+50;
vector <pLL> edge[N];
vector <pLL> f[N];
vector <pLL> tl, tr;
LL lim;
inline void inc(int x,const pLL &t) {
    if(f[x].size() && f[x].back()<=t) return;
    while(f[x].size() && f[x].back().second>=t.second) f[x].pop_back();
    f[x].push_back(t);
}
inline bool dfs(int x,int fa) {
    f[x].clear();
    if(edge[x].size()==1) {f[x].push_back(pLL(0,0)); return true;} 
    LL lc,rc,disl,disr; int fir=0;
    for(int e=edge[x].size()-1;e>=0;e--) {
        int v=edge[x][e].first; if(v==fa) continue;
        if(!dfs(v,x)) return false;
        if(!fir) fir=1, lc=v, disl=edge[x][e].second;
        else rc=v, disr=edge[x][e].second;
    }
    tl.clear(), tr.clear(); LL lim2=lim-disl-disr;
    if(lim2<0) return false; 
    for(int p1=0,p2=0;p2<f[rc].size();p2++) {
        while(p1<f[lc].size() && f[lc][p1].first+f[rc][p2].second>lim2) ++p1;
        if(p1==f[lc].size()) break;
        tl.push_back(pLL(f[rc][p2].first+disr,f[lc][p1].second+disl));
    }
    for(int p1=0,p2=0;p1<f[lc].size();p1++) {
        while(p2<f[rc].size() && f[lc][p1].second+f[rc][p2].first>lim2) ++p2;
        if(p2==f[rc].size()) break;
        tr.push_back(pLL(f[lc][p1].first+disl,f[rc][p2].second+disr));
    }
    int pl=0, pr=0;
    while(pl<tl.size() && pr<tr.size()) {
        if(tl[pl].first>tr[pr].first) inc(x,tl[pl++]);
        else inc(x,tr[pr++]);
    }
    while(pl<tl.size()) inc(x,tl[pl++]);
    while(pr<tr.size()) inc(x,tr[pr++]);
    return f[x].size()>0;
}
inline bool check(LL v) { lim=v; return dfs(1,0);}
int main() {
    int n=rd();
    for(int i=2;i<=n;i++) {
        int x=rd(), w=rd();
        edge[x].push_back(pLL(i,w));
        edge[i].push_back(pLL(x,w));
    }
    LL l=0, r=1e12, ans=0;
    while(l<=r) {
        LL mid=(l+r)>>1;
        if(check(mid)) ans=mid, r=mid-1;
        else l=mid+1;
    } cout<<ans;
}

Compiler output:
a.cc:19:9: error: 'pLL' was not declared in this scope; did you mean 'LL'?
   19 | vector <pLL> edge[N];
      |         ^~~
      |         LL
a.cc:19:12: error: template argument 1 is invalid
   19 | vector <pLL> edge[N];
      |            ^
a.cc:19:12: error: template argument 2 is invalid
a.cc:20:9: error: 'pLL' was not declared in this scope; did you mean 'LL'?
   20 | vector <pLL> f[N];
      |         ^~~
      |         LL
a.cc:20:12: error: template argument 1 is invalid
   20 | vector <pLL> f[N];
      |            ^
a.cc:20:12: error: template argument 2 is invalid
a.cc:21:9: error: 'pLL' was not declared in this scope; did you mean 'LL'?
   21 | vector <pLL> tl, tr;
      |         ^~~
      |         LL
a.cc:21:12: error: template argument 1 is invalid
   21 | vector <pLL> tl, tr;
      |            ^
a.cc:21:12: error: template argument 2 is invalid
a.cc:23:29: error: 'pLL' does not name a type; did you mean 'LL'?
   23 | inline void inc(int x,const pLL &t) {
      |                             ^~~
      |                             LL
a.cc: In function 'void inc(int, const int&)':
a.cc:24:13: error: request for member 'size' in 'f[x]', which is of non-class type 'int'
   24 |     if(f[x].size() && f[x].back()<=t) return;
      |             ^~~~
a.cc:24:28: error: request for member 'back' in 'f[x]', which is of non-class type 'int'
   24 |     if(f[x].size() && f[x].back()<=t) return;
      |                            ^~~~
a.cc:25:16: error: request for member 'size' in 'f[x]', which is of non-class type 'int'
   25 |     while(f[x].size() && f[x].back().second>=t.second) f[x].pop_back();
      |                ^~~~
a.cc:25:31: error: request for member 'back' in 'f[x]', which is of non-class type 'int'
   25 |     while(f[x].size() && f[x].back().second>=t.second) f[x].pop_back();
      |                               ^~~~
a.cc:25:48: error: request for member 'second' in 't', which is of non-class type 'const int'
   25 |     while(f[x].size() && f[x].back().second>=t.second) f[x].pop_back();
      |                                                ^~~~~~
a.cc:25:61: error: request for member 'pop_back' in 'f[x]', which is of non-class type 'int'
   25 |     while(f[x].size() && f[x].back().second>=t.second) f[x].pop_back();
      |                                                             ^~~~~~~~
a.cc:26:10: error: request for member 'push_back' in 'f[x]', which is of non-class type 'int'
   26 |     f[x].push_back(t);
      |          ^~~~~~~~~
a.cc: In function 'bool dfs(int, int)':
a.cc:29:10: error: request for member 'clear' in 'f[x]', which is of non-class type 'int'
   29 |     f[x].clear();
      |          ^~~~~
a.cc:30:16: error: request for member 'size' in 'edge[x]', which is of non-class type 'int'
   30 |     if(edge[x].size()==1) {f[x].push_back(pLL(0,0)); return true;}
      |                ^~~~
a.cc:30:33: error: request for member 'push_back' in 'f[x]', which is of non-class type 'int'
   30 |     if(edge[x].size()==1) {f[x].push_back(pLL(0,0)); return true;}
      |                                 ^~~~~~~~~
a.cc:30:43: error: 'pLL' was not declared in this scope; did you mean 'LL'?
   30 |     if(edge[x].size()==1) {f[x].push_back(pLL(0,0)); return true;}
      |                                           ^~~
      |                                           LL
a.cc:32:23: error: request for member 'size' in 'edge[x]', which is of non-class type 'int'
   32 |     for(int e=edge[x].size()-1;e>=0;e--) {
      |                       ^~~~
a.cc:33:22: error: invalid types 'int[int]' for array subscript
   33 |         int v=edge[x][e].first; if(v==fa) continue;
      |                      ^
a.cc:35:43: error: invalid types 'int[int]' for array subscript
   35 |         if(!fir) fir=1, lc=v, disl=edge[x][e].second;
      |                                           ^
a.cc:36:32: error: invalid types 'int[int]' for array subscript
   36 |         else rc=v, disr=edge[x][e].second;
      |                                ^
a.cc:38:8: error: request for member 'clear' in 'tl', which is of non-class type 'int'
   38 |     tl.clear(), tr.clear(); LL lim2=lim-disl-disr;
      |        ^~~~~
a.cc:38:20: error: request for member 'clear' in 'tr', which is of non-class type 'int'
   38 |     tl.clear(), tr.clear(); LL lim2=lim-disl-disr;
      |                    ^~~~~
a.cc:40:32: error: request for member 'size' in 'f[rc]', which is of non-class type 'int'
   40 |     for(int p1=0,p2=0;p2<f[rc].size();p2++) {
      |                                ^~~~
a.cc:41:24: error: request for member 'size' in 'f[lc]', which is of non-class type 'int'
   41 |         while(p1<f[lc].size() && f[lc][p1].first+f[rc][p2].second>lim2) ++p1;
      |                        ^~~~
a.cc:41:39: error: invalid types 'int[int]' for array subscript
   41 |         while(p1<f[lc].size() && f[lc][p1].first+f[rc][p2].second>lim2) ++p1;
      |                                       ^
a.cc:41:55: error: invalid types 'int[int]' for array subscript
   41 |         while(p1<f[lc].size() && f[lc][p1].first+f[rc][p2].second>lim2) ++p1;
      |                                                       ^
a.cc:42:22: error: request for member 'size' in 'f[lc]', which is of non-class type 'int'
   42 |         if(p1==f[lc].size()) break;
      |                      ^~~~
a.cc:43:12: error: request for member 'push_back' in 'tl', which is of non-class type 'int'
   43 |         tl.push_back(pLL(f[rc][p2].first+disr,f[lc][p1].second+disl));
      |            ^~~~~~~~~
a.cc:43:31: error: invalid types 'int[int]' for array subscript
   43 |         tl.push_back(pLL(f[rc][p2].first+disr,f[lc][p1].second+disl));
      |                               ^
a.cc:43:52: error: invalid types 'int[int]' for array subscript
   43 |         tl.push_back(pLL(f[rc][p2].first+disr,f[lc][p1].second+disl));
      |                                                    ^
a.cc:43:22: error: 'pLL' was not declared in this scope; did you mean 'LL'?
   43 |         tl.push_back(pLL(f[rc][p2].first+disr,f[lc][p1].second+disl));
      |                      ^~~
      |                      LL
a.cc:45:32: error: request for member 'size' in 'f[lc]', which is of non-class type 'int'
   45 |     for(int p1=0,p2=0;p1<f[lc].size();p1++) {
      |                                ^~~~
a.cc:46:24: error: request for member 'size' in 'f[rc]', which is of non-class type 'int'
   46 |         while(p2<f[rc].size() && f[lc][p1].second+f[rc][p2].first>lim2) ++p2;
      |                        ^~~~
a.cc:46:39: error: invalid types 'int[int]' for array subscript
   46 |         while(p2<f[rc].size() && f[lc][p1].second+f[rc][p2].first>lim2) ++p2;
      |                                       ^
a.cc:46:56: error: invalid types 'int[int]' for array subscript
   46 |         while(p2<f[rc].size() && f[lc][p1].second+f[rc][p2].first>lim2) ++p2;
      |                                                        ^
a.cc:47:22: error: request for member 'size' in 'f[rc]', which is of non-class type 'int'
   47 |         if(p2==f[rc].size()) break;
      |                      ^~~~
a.cc:48:12: error: request for member 'push_back' in 'tr', which is of non-class type 'int'
   48 |         tr.push_back(pLL(f[lc][p1].first+disl,f[rc][p2].second+disr));
      |            ^~~~~~~~~
a.cc:48:31: error: invalid types 'int[int]' for array subscript
   48 |         tr.push_back(pLL(f[lc][p1].first+disl,f[rc][p2].second+disr));
      |                               ^
a.cc:48:52: error: invalid types 'int[int]' for array subscript
   48 |         tr.push_back(pLL(f[lc][p1].first+disl,f[rc][p2].second+disr));
      |                                                    ^
a.cc:48:22: error: 'pLL' was not declared in this scope; did you mean 'LL'?
   48 |         tr.push_back(pLL(f[lc][p1].first+disl,f[rc][p2].second+disr));
      |                      ^~~
      |                      LL
a.cc:51:17: error: request for member 'size' in 'tl', which is of non-class type 'int'
   51 |     while(pl<tl.size() && pr<tr.size()) {
      |                 ^~~~
a.cc:51:33: error: request for member 'size' in 'tr', which is of non-class type 'int'
   51 |     while(pl<tl.size() && pr<tr.size()) {
      |                                 ^~~~
a.cc:52:14: error: invalid types 'int[int]' for array subscript
   52 |         if(tl[pl].first>tr[pr].first) inc(x,tl[pl++]);
      |              ^
a.cc:52:27: error: invalid types 'int[int]' for array subscript
   52 |         if(tl[pl].first>tr[pr].first) inc(x,tl[pl++]);
      |                           ^
a.cc:52:47: error: invalid types 'int[int]' for array subscript
   52 |         if(tl[pl].first>tr[pr].first) inc(x,tl[pl++]);
      |                                               ^
a.cc:53:22: error: invalid types 'int[int]' for array subscript
   53 |         else inc(x,tr[pr++]);
      |                      ^
a.cc:55:17: error: request for member 'size' in 'tl', which is of non-class type 'int'
   55 |     while(pl<tl.size()) inc(x,tl[pl++]);
      |                 ^~~~
a.cc:55:33: error: invalid types 'int[int]' for array subscript
   55 |     while(pl<tl.size()) inc(x,tl[pl++]);
      |                                 ^
a.cc:56:17: error: request for member 'size' in 'tr', which is of non-class type 'int'
   56 |     while(pr<tr.size()) inc(x,tr[pr++]);
      |                 ^~~~
a.cc:56:33: error: invalid types 'int[int]' for array subscript
   56 |     while(pr<tr.size()) inc(x,tr[pr++]);
      |                                 ^
a.cc:57:17: error: request for member 'size' in 'f[x]', which is of non-class type 'int'
   57 |     return f[x].size()>0;
      |                 ^~~~
a.cc: In function 'int main()':
a.cc:64:17: error: request for member 'push_back' in 'edge[x]', which is of non-class type 'int'
   64 |         edge[x].push_back(pLL(i,w));
      |                 ^~~~~~~~~
a.cc:64:27: error: 'pLL' was not declared in this scope; did you mean 'LL'?
   64 |         edge[x].push_back(pLL(i,w));
      |                           ^~~
      |                           LL
a.cc:65:17: error: request for member 'push_back' in 'edge[i]', which is of non-class type 'int'
   65 |         ed