c++ 80' #2WA 求助大佬
查看原帖
c++ 80' #2WA 求助大佬
557826
D_guard楼主2022/2/19 17:14

没有建树,按照“子节点的深度为父节点深度+1”的思路而做

蒟蒻代码如下:

#include <iostream>
#include <cmath>
using namespace std;
int n, l, r, m, dep[1000001]={0,1};
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>l>>r;
		if(l)	dep[l]=dep[i]+1;
		if(r)	dep[r]=dep[i]+1;
		if(!(l || r))	m=max(m,dep[i]);
	}
	cout<<m;
	return 0;
}

#2错误反馈:

wrong answer On line 1 column 1,read 5,expected 4

2022/2/19 17:14
加载中...