Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
99657 | 梁晨熙 | 树的深度 | C++ | 通过 | 100 | 0 MS | 256 KB | 390 | 2023-08-23 14:49:23 |
#include<bits/stdc++.h> using namespace std; int n; int ans; struct node{ int l,r; }tree[100001]; void dfs(int id,int step){ if(tree[id].l==0&&tree[id].r==0){ ans=max(ans,step); return; } dfs(tree[id].l,step+1); dfs(tree[id].r,step+1); } int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>tree[i].l>>tree[i].r; } dfs(1,1); cout<<ans<<endl; return 0; }