80分蒟蒻WA#2求助
查看原帖
80分蒟蒻WA#2求助
375668
Leville楼主2021/3/7 16:24
#include<iostream>
using namespace std;
const int N=1000001;
struct node{
	int left,right,depth;
}a[N];
int dfs(int index){
	if(a[index].left==0&&a[index].right==0)
		return a[index].depth;
	if(a[index].left==0)
		return dfs(a[index].right);
	if(a[index].right==0)
		return dfs(a[index].left);
	return max(dfs(a[index].right),dfs(a[index].left));
}
int main(){
	int n;
	cin>>n;
	cin>>a[1].left>>a[1].right;
	a[1].depth=1;
	a[a[1].left].depth=a[a[1].right].depth=a[1].depth+1;
	for(int t=2;t<=n;t++){
		cin>>a[t].left>>a[t].right;
		a[a[t].left].depth=a[a[t].right].depth=a[t].depth+1;
	}
	cout<<dfs(1);
	return 0;
}

码风凌乱求谅解

2021/3/7 16:24
加载中...