QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#757654#9751. 覆盖一棵树Jumping#WA 395ms9112kbC++141.3kb2024-11-17 11:52:172024-11-17 11:52:18

Judging History

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

  • [2024-11-17 11:52:18]
  • 评测
  • 测评结果:WA
  • 用时:395ms
  • 内存:9112kb
  • [2024-11-17 11:52:17]
  • 提交

answer

#include<bits/stdc++.h>
#define gt getchar
#define pt putchar
#define ll 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);
}
int dp[MAXN],ans=-1;
int outd[MAXN];
void dfs(int u,int fa){
	if(!outd[u]){
		dp[u]=0;
		return;
	}
	for(int v:g[u]){
		if(v==fa)continue;
		dfs(v,u);
		dp[u]=min(dp[u],dp[v]+1);
		ans=max(ans,dp[v]+1);
	}
}
void solve(){
	ans=-1;
	memset(dp,0x3f,sizeof(dp));
	int n=read();
	for(int i=2;i<=n;i++){
		int p=read();
		add_edge(p,i);
		outd[p]++;
	}
	add_edge(1,0); 
	dfs(1,0);
	cout<<ans<<'\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: 9112kb

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: 395ms
memory: 9048kb

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:

4
1061109568
1061109568
1061109568
1061109568
1061109568
1061109568
1061109568
1061109568
1061109568
9
1061109568
1061109568
9
1061109568
1061109568
1061109568
1061109568
1061109568
1061109568
1061109568
1061109568
1061109568
1061109568
1061109568
1061109568
1061109568
1061109568
9
1061109568
106110...

result:

wrong answer 2nd lines differ - expected: '8', found: '1061109568'