Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
99651 | 王为治 | 树的深度 | C++ | 通过 | 100 | 0 MS | 256 KB | 406 | 2023-08-23 14:46:03 |
#include <bits/stdc++.h> using namespace std; int n,ans=-0x3f3f3f3f; struct node{ int left,right; }tree[1000005]; void dfs(int p, int deep) { if(p == 0)return; ans = max(ans,deep); dfs(tree[p].left,deep+1); dfs(tree[p].right,deep+1); } signed main() { cin >> n; for(int i = 1; i <= n; i++)cin>>tree[i].left>>tree[i].right; dfs(1,1); cout << ans << endl; return 0; }