#include<cstdio>
#include<iostream>
using namespace std;
struct node {
int from,to,next;
};
struct node edge[1000];
int n,num,head[60],ans_h,w[100],ans_w;
inline void edge_add(int from,int to)
{
num++;
edge[num].to=to;
edge[num].from=from;
edge[num].next=head[from];
head[from]=num;
}
void search(int now,int now_)
{
ans_h=max(now_,ans_h),w[now_]++;
for(int i=head[now];i!=0;i=edge[i].next) search(edge[i].to,now_+1);
}
int main()
{
scanf("%d",&n);
int ch_l,ch_r;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&ch_l,&ch_r);
if(ch_l) edge_add(i,ch_l);
if(ch_r) edge_add(i,ch_r);
}
search(1,1);
for(int i=1;i<=ans_h;i++) ans_w=max(ans_w,w[i]);
printf("%d %d\n",ans_w,ans_h);
return 0;
}