提交时间:2021-05-27 21:47:47

运行 ID: 20011

#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; }