QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#75717#5455. TreeScriptchenshi#WA 22ms5704kbC++925b2023-02-06 09:00:052023-02-06 09:00:07

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-06 09:00:07]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:5704kb
  • [2023-02-06 09:00:05]
  • 提交

answer

#include<cstdio>
#include<algorithm>
using namespace std;
const int o=2e5+10;
int T,n,p[o],h[o],cnt,f[o],g[o],st[o],tp;
struct Edge{int v,p;}e[o];
inline void ad(int U,int V){e[++cnt].v=V;e[cnt].p=h[U];h[U]=cnt;}
inline bool cmp(int A,int B){return g[A]<g[B];}
inline bool Cmp(int A,int B){return f[A]<f[B];}
void dfs(int nw){
	for(int i=h[nw];i;i=e[i].p) dfs(e[i].v);
	tp=0;
	for(int i=h[nw];i;i=e[i].p) st[++tp]=e[i].v;
	if(!tp){f[nw]=g[nw]=1;return;}
	sort(st+1,st+tp+1,cmp);
	f[nw]=g[nw]=g[st[tp]]+1;
	sort(st+1,st+tp+1,Cmp);
	for(int l=1,r=f[nw],md,res;l<r;f[nw]=l){
		md=l+r>>1;res=1;
		for(int i=tp,s=0;i;--i) if(g[st[i]]+1>md) res=max(res,f[st[i]]+s),++s;
		if(res<=md) r=md;else l=md+1;
	}
}
int main(){
	for(scanf("%d",&T);T--;printf("%d\n",f[1]),cnt=0){
		scanf("%d",&n);
		for(int i=1;i<=n;++i) scanf("%d",&p[i]),h[i]=0;
		for(int i=2;i<=n;++i) ad(p[i],i);
		dfs(1);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 5604kb

input:

2
3
0 1 2
7
0 1 2 2 1 4 1

output:

1
2

result:

ok 2 number(s): "1 2"

Test #2:

score: -100
Wrong Answer
time: 22ms
memory: 5704kb

input:

1000
197
0 1 1 2 1 4 1 5 8 3 5 1 4 7 12 14 4 7 10 9 12 11 16 10 21 19 22 17 25 13 28 9 5 15 26 26 33 25 15 1 35 6 32 17 37 8 19 43 19 27 29 9 30 6 31 27 35 35 37 13 28 38 57 31 38 8 22 14 33 9 18 62 52 37 10 19 22 60 54 12 38 59 64 65 80 82 28 60 85 78 27 25 71 14 52 6 59 14 87 32 33 41 59 41 88 38 ...

output:

7
5
3
5
4
5
5
6
4
5
6
5
7
6
4
4
6
7
4
6
7
3
5
5
5
5
7
4
5
8
3
6
4
4
6
5
4
4
3
4
5
5
4
3
5
5
7
6
4
5
5
3
4
6
7
5
5
6
5
6
6
6
3
6
5
5
4
5
7
5
4
7
7
6
6
6
3
3
6
1
1
7
7
4
4
5
7
8
5
5
5
6
5
5
4
5
4
5
5
6
6
5
5
7
5
5
3
3
7
5
5
4
4
3
6
4
4
2
5
5
3
6
4
8
3
5
5
4
6
5
7
5
6
5
5
4
7
5
5
3
3
4
4
2
7
6
4
2
5
6
...

result:

wrong answer 1st numbers differ - expected: '4', found: '7'