QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#504612#9101. Zayin and BusAnotherDayofSun#AC ✓86ms7980kbC++201.4kb2024-08-04 14:06:042024-08-04 14:06:04

Judging History

你现在查看的是最新测评结果

  • [2024-08-04 14:06:04]
  • 评测
  • 测评结果:AC
  • 用时:86ms
  • 内存:7980kb
  • [2024-08-04 14:06:04]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,j,k) for(int i=(j);i<=(k);i++)
#define foR(i,j,k) for(int i=(j);i>=(k);i--) 
#define vi vector<int>
#define pb push_back
#define pii pair<int,int> 
#define mkp make_pair
#define SZ(x) ((int)x.size())

using namespace std;
inline int read() {
	char c;int res=0;bool flag=0;
	while(c=getchar(),c<48)(c=='-')&&(flag=1);
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>47);
	flag&&(res=-res); return res; 
}
const int MN=2e5+5;
const int N=MN; 
int head[N],to[N<<1],nxt[N<<1],cnt1;
inline void adde(int x,int y){to[++cnt1]=y;nxt[cnt1]=head[x];head[x]=cnt1;}
int a[N],dep[N],fa[N];
void dfs(int x,int f){
	dep[x]=dep[f]+1;
	for(int i=head[x];i;i=nxt[i]){
		int y=to[i];
		if(y==f)continue;
		dfs(y,x);
	}
}
int n;
void works() {
	n=read();
	for(int i=2;i<=n;i++){
		fa[i]=read();
		adde(fa[i],i);
//		int x=read(),y=read();
//		adde(x,y);
//		adde(y,x);	
	}
	for(int i=1;i<=n;i++){
		a[i]=read();
		a[i]+=i;
	}
	sort(a+1,a+n+1);
	dfs(1,0);
	sort(dep+1,dep+n+1);
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=max(ans,a[i]+dep[n-i+1]-1);
	printf("%d\n",ans);
	for(int i=1;i<=n;i++)dep[i]=0,head[i]=0;
	cnt1=0;
	
}
signed main() {
//	#ifdef wasa855
//		freopen("pro.in","r",stdin); 
//		freopen("pro.out","w",stdout); 
//	#endif
	int T=read(); 
	while(T--) {
		works(); 	
	}
	return 0; 	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7980kb

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: 86ms
memory: 7964kb

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