#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
using namespace std;
const int Max = 1e6 + 10;
int n, ans = 0;
struct node
{
int left, right;
};
node tree[Max];
void dfs(int root, int deep)
{
if (root == 0)
return;
ans = max(ans, deep);
dfs(tree[root].left, deep + 1);
dfs(tree[root].right, deep + 1);
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> tree[i].left >> tree[i].right;
}
dfs(1, 1);
cout << ans << endl;
}
求二叉树深度
最新推荐文章于 2024-09-02 16:35:28 发布