Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
99656 黄戈 树的深度 C++ 通过 100 0 MS 256 KB 444 2023-08-23 14:49:19

Tests(8/8):


#include<cstdio> #include<cstring> #include<queue> #include<iostream> using namespace std; struct Edge{ int ls,rs; }; int mx; Edge e[1000005]; void dfs(int u,int depth){ mx=max(depth,mx); if(e[u].ls !=0) dfs(e[u].ls,depth+1); if(e[u].rs !=0) dfs(e[u].rs,depth+1); } int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d %d",&e[i].ls,&e[i].rs); } dfs(1,1); printf("%d\n",mx); return 0; }


测评信息: