P4913 (洛谷)
洛谷 P4913
https://www.luogu.com.cn/problem/P4913
思路
对于两个子节点,进行深度搜索
代码
#include <bits/stdc++.h>
using namespace std;
struct tree{
int l,r;
};
tree a[1000005];
int n;
int fs(int x,int y){
if(!x) return 0;
return 1+max(fs(a[x].l,y+1),fs(a[x].r,y+1));
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].l>>a[i].r;
}cout<<fs(1,1);
return 0;
}
6月10日 第一篇
蒟蒻冲刺六级NO.1
日志
6.10发布
6.11精简代码