40,WA#2,MLE#3#5,求条
查看原帖
40,WA#2,MLE#3#5,求条
1159387
littlejohn楼主2025/2/5 11:25
#include<bits/stdc++.h>
using namespace std;
struct nood{
	int l,r;
};
struct nood2{
	int x,num;
};
nood a[1000005];
int n,l,r,ans;
queue<nood2> q; nood2 temp;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&l,&r);
		a[i].l = l;
		a[i].r = r;
	}
	q.push({1,1});
	while(!q.empty()){
		temp = q.front();
		q.pop();
		ans = max(ans,temp.num);
		if(a[temp.num].l!=0)q.push({a[temp.num].l , temp.num+1});
		if(a[temp.num].r!=0)q.push({a[temp.num].r , temp.num+1});
	}
	cout<<ans;
	return 0;
}

2025/2/5 11:25
加载中...