提交时间:2021-05-27 20:58:16
运行 ID: 19992
#include<iostream> using namespace std; int n,deep,wide,maxd; int a[1005][3],w[1005]; 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() { int i,x; 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; }