这份代码是不是加上dfs里的注释部分就能过?
补题还没开放
#include <bits/stdc++.h>
using namespace std;
#define sp putchar(' ')
#define en putchar('\n')
#define pb push_back
#define int long long
#define P 998244353
#define HP 1000000000000002097
#define N (int)(2e5+5)
int read(){ char ch=getchar();int x=0,f=1;while(ch>'9' || ch<'0'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();return x*f; }
void print(int x){ if(x<0) putchar('-'),x=-x;if(x>9)print(x/10);putchar(x%10+'0'); }
int n;
bool f;
vector<int> e[N];
int a[N];
void dfs(int u,int tag)
{
/*if(tag>=2e9){
f=1;
return;
}*/
bool ff=0;
for(auto v:e[u]){
ff=1;
dfs(v,tag*2-a[v]);
}
if(!ff){
if(tag>a[u]) f=1;
}
}
bool check(int x)
{
f=0;
dfs(1,x-a[1]);
return (f==0);
}
void solve()
{
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i],e[i].clear();
if(n==1){
cout<<a[1];
return;
}
for(int i=2,u;i<=n;i++){
cin>>u;
e[u].pb(i);
}
int l=a[1],r=1e15,ans=a[1];
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)) l=mid+1,ans=mid;
else r=mid-1;
}
cout<<ans<<"\n";
}
main()
{
ios::sync_with_stdio(0);cin.tie(0),cout.tie(0);
int T;
cin>>T;
while(T--){
solve();
}
return 0;
}