QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#757620#9751. 覆盖一棵树Jumping#WA 6ms9732kbC++141.3kb2024-11-17 11:16:122024-11-17 11:16:12

Judging History

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

  • [2024-11-17 11:16:12]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:9732kb
  • [2024-11-17 11:16:12]
  • 提交

answer

#include<bits/stdc++.h>
#define gt getchar
#define pt putchar
#define int long long
#define ull unsigned long long
#define fst first
#define snd second
#define L(x) x<<1
#define R(x) x<<1|1
using namespace std;
typedef pair<int,int> pii;
const double eps=1e-8;
inline bool pts(char ch){return ch>=48&&ch<=57;}
inline int read(){
	bool f=0;int x=0;char ch;
	ch=gt();
	while(!pts(ch)&&ch!=EOF){if(ch=='-')f=1;ch=gt();}
	while(pts(ch)){x*=10;x+=(ch-48);ch=gt();}
	if(f)return -x;
	else return x;
}
template<class T>
inline void print(T x){
	char s[114];
	int top=0;
	if(x<0)pt('-');
	do{
		top++;
		if(x>=0)s[top]=(x%10)+48;
		else s[top]=(-(x%10)+48);
		x/=10;
	}while(x);
	while(top){pt(s[top]);top--;}
}
const int MAXN=2e5+10;
vector<int>g[MAXN];
void add_edge(int u,int v){
	g[u].push_back(v);
	g[v].push_back(u);
}
int dep[MAXN];
void dfs(int u,int fa){
	dep[u]=dep[fa]+1;
	for(int v:g[u]){
		if(v==fa)continue;
		dfs(v,u);
	}
}
void solve(){
	
	int n=read();
	for(int i=2;i<=n;i++){
		int p=read();
		add_edge(i,p);
	}
	add_edge(1,0); 
	dfs(1,0);
	int maxn=-1;
	for(int i=1;i<=n;i++)maxn=max(maxn,dep[i]);
	cout<<maxn-1<<'\n';for(int i=0;i<=n;i++)g[i].clear();
}
signed main(){
	int T=read();
	while(T--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

3
7

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 6ms
memory: 9572kb

input:

33428
10
1 2 3 3 4 6 7 7 9
10
1 2 3 4 5 6 7 8 8
8
1 2 3 4 5 6 7
8
1 2 3 4 4 6 7
4
1 2 3
3
1 2
3
1 1
9
1 2 3 4 5 6 7 8
2
1
3
1 2
10
1 2 3 4 5 6 7 8 9
3
1 2
2
1
10
1 2 3 4 5 6 7 8 9
2
1
5
1 2 2 4
8
1 2 3 4 5 6 7
5
1 2 3 3
2
1
5
1 2 3 4
3
1 2
9
1 2 3 4 5 6 6 8
9
1 2 3 4 5 6 7 8
9
1 2 3 4 5 5 7 8
8
1 2 ...

output:

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

result:

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