| Run ID | Author | Problem | Lang | Verdict | Score | Time | Memory | Code Length | Submit Time |
|---|---|---|---|---|---|---|---|---|---|
| 20011 | 桑迪 | 二叉树的深度和宽度 | C++ | Accepted | 100 | 0 MS | 260 KB | 416 | 2021-05-27 21:47:47 |
#include<bits/stdc++.h> using namespace std; int n,deep,wide,maxd; int a[1005][3],w[1005],i,x; void dfs(int x) { if(x==0)return; deep++; w[deep]++; if(deep>maxd)maxd=deep; dfs(a[x][1]); dfs(a[x][2]); deep--; return; } int main(){ cin>>n; for(i=1;i<=n;++i){ cin>>x>>a[i][1]>>a[i][2]; } dfs(1); for(i=1;i<=maxd;++i) if(w[i]>wide)wide=w[i]; cout<<maxd<<" "<<wide; return 0; }