首页 > 其他 > 详细

P4913 【深基16.例3】二叉树深度

时间:2020-08-12 18:56:12      阅读:66      评论:0      收藏:0      [点我收藏+]

https://www.luogu.com.cn/problem/P4913

#include<bits/stdc++.h>
using namespace std;
struct node{
    int l, r;
};
node a[1000005];
int n, ans=-1;
void dfs(int root, int deep){
    if(root==0)return;
    ans=max(ans,deep);
    dfs(a[root].l, deep+1);
    dfs(a[root].r, deep+1);
}
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i].l>>a[i].r;
    dfs(1,1);
    cout<<ans;
    
    return 0;
 } 

 

P4913 【深基16.例3】二叉树深度

原文:https://www.cnblogs.com/tflsnoi/p/13491912.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!