QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#504737 | #9101. Zayin and Bus | Lavender_Field# | AC ✓ | 66ms | 10356kb | C++20 | 1.1kb | 2024-08-04 15:28:30 | 2024-08-04 15:28:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
int T,n;
struct node{
int to,nxt;
}e[N];
int cnt,head[N];
void add(int u,int v){
e[++cnt].to=v;
e[cnt].nxt=head[u];
head[u]=cnt;
}
int rd() {
int r = 0; bool w = false; char ch = getchar();
while( ch < '0' || ch > '9' ) w = !(ch^45), ch = getchar();
while( ch >= '0' && ch <= '9' ) r = (r<<1) + (r<<3) + (ch^48), ch = getchar();
return w ? -r : r;
}
int a[N];
int dep[N];
void dfs(int u,int Dep){
dep[Dep]++;
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
dfs(v,Dep+1);
}
}
void solve(){
n=rd();cnt=0;
for(int i=1;i<=n;i++) head[i]=0;
for(int i=1,x;i<n;i++){
x=rd();add(x,i+1);
}
dep[0]=0;
for(int i=1;i<=n;i++){
a[i]=rd();
a[i]=-i-a[i];
dep[i]=0;
}
sort(a+1,a+1+n);
dfs(1,0);
int now=0,ans=0;
for(int i=1;i<=n;i++){
while(dep[now]==0) now++;
ans=max(ans,now-a[i]);
dep[now]--;
}
printf("%d\n",ans);
}
int main(){
scanf("%d",&T);
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 10040kb
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: 66ms
memory: 10356kb
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