QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#504693 | #9101. Zayin and Bus | blhxzjr# | AC ✓ | 165ms | 13068kb | C++20 | 2.2kb | 2024-08-04 14:55:30 | 2024-08-04 14:55:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define lowbit(x) (x & (-x))
#define all(x) x.begin(), x.end()
#define inf 0x3f3f3f3f3f3f3f3f
#define int long long
using ll = long long;
using PII = pair<int, int>;
constexpr int N = 1e5 + 10;
using LD = long double;
mt19937_64 rnd(chrono::duration_cast<chrono::nanoseconds>(chrono::system_clock::now().time_since_epoch()).count());
int n,m,k,_;
// const int M=N*70;
// int t[M],ls[M],rs[M];
// int tot,root;
// inline void up(int id){
// t[id]=t[ls[id]]+t[rs[id]];
// }
// void modify(int &id,int l,int r,int x,int v){
// if(!id) id=++tot;
// if(l==r){
// t[id]+=v; return;
// }
// int mid=l+r>>1;
// if(x<=mid) modify(ls[id],l,mid,x,v);
// else modify(rs[id],mid+1,r,x,v);
// up(id);
// }
// int query(int id,int l,int r,int ql,int qr){
// if(ql<=l&&r<=qr){
// return t[id];
// }
// int mid=l+r>>1;
// if(qr<=mid) return query(ls[id],l,mid,ql,qr);
// else if(ql>mid) return query(rs[id],mid+1,r,ql,qr);
// else return query(ls[id],l,mid,ql,qr)+query(rs[id],mid+1,r,ql,qr);
// }
// void solve(){
// cin>>n>>m;
// int op,l,r,v;
// rep(i,1,m){
// cin>>op>>l;
// if(op==1){
// cin>>v;
// for(int j=l;j<=n;j+=lowbit(j)){
// modify(root,1,n,j,v);
// }
// }
// else{
// cin>>r;
// cout<<query(root,1,n,l,r)<<endl;
// }
// }
// }
int a[N],d[N];
vector<int>g[N];
void dfs(int id,int fa,int dep){
d[id]=-dep;
for(auto son:g[id]){
if(son==fa) continue;
dfs(son,id,dep+1);
}
}
void solve(){
cin>>n;
rep(i,1,n) g[i].clear(),d[i]=0;
rep(i,1,n-1){
cin>>m;
g[m].pb(i+1);
g[i+1].pb(m);
}
rep(i,1,n) cin>>a[i],a[i]+=i;
dfs(1,0,0);
int ans=0;
sort(d+1,d+1+n);
sort(a+1,a+1+n);
rep(i,1,n){
ans=max(ans,-d[i]+a[i]);
}
cout<<ans;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
_ = 1;
cin >> _;
while (_--)
{
solve();
// clear();
if (_)
cout << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5712kb
input:
14 1 1 1 2 1 3 2 1 1 1 2 1 1 2 2 1 2 1 2 1 1 3 2 1 3 1 2 1 1 4 2 1 4 1 3 1 1 1 1 1 3 1 2 1 1 1 3 1 1 1 3 2 3 1 2 1 3 2
output:
2 3 4 3 4 4 5 4 6 5 4 4 6 6
result:
ok 14 lines
Test #2:
score: 0
Accepted
time: 165ms
memory: 13068kb
input:
15 1000 1 2 2 1 1 1 4 8 1 7 7 7 9 3 4 7 15 18 18 4 6 11 19 7 6 1 9 13 2 21 28 6 17 24 24 2 28 5 32 24 23 8 3 26 15 28 25 34 46 41 33 16 46 11 7 2 13 53 12 59 52 53 51 52 31 41 63 18 55 49 55 62 15 19 23 67 18 37 2 4 23 75 58 55 14 84 20 3 7 89 82 15 53 77 60 25 97 69 5 40 54 24 72 10 87 90 99 43 71 ...
output:
98572828 100088663 99870474 100076153 99995412 100076982 99971239 100079684 99928633 100093408 99432584 100093568 99620300 100058966 99565256
result:
ok 15 lines