/*H E A D*/
int to[maxn<<1],nxt[maxn<<1],cost[maxn<<1],head[maxn],tot;
int size[maxn],fa[maxn],depth[maxn],top[maxn],son[maxn],dfn[maxn],pre[maxn],tot2;
void init(){
memset(head,-1,sizeof head);
memset(son,0,sizeof son);
memset(size,0,sizeof size);
memset(fa,0,sizeof fa);
tot=tot2=0;
}
void add(int u,int v,int w=0){
to[tot]=v;nxt[tot]=head[u];cost[tot]=w;
head[u]=tot++;
swap(u,v);
to[tot]=v;nxt[tot]=head[u];cost[tot]=w;
head[u]=tot++;
}
void dfs(int u,int p,int d){
size[u]=1;fa[u]=p;depth[u]=d;
erep(i,u){
int v=to[i];
if(v==p)continue;
dfs(v,u,d+1);
size[u]+=size[v];
if(size[v]>size[son[u]]){//update
son[u]=v;
}
}
}
void dfs2(int u,int tp){
pre[++tot2]=u;
dfn[u]=tot2;
top[u]=tp;
if(son[u]) dfs2(son[u],tp);//heavy --- ori top
erep(i,u){
int v=to[i];
if(v==son[u]||v==fa[u])continue;
dfs2(v,v);//light --- themselves
}
}
int main(){
int u,v;
init();
while(cin>>u>>v){
if(~u) add(u,v);
else{
dfs(1,0,1);
dfs2(1,1);
cout<<tot2<<endl;
for(int i = 1; i <= tot2; i++){
cout<<i<<" "<<"size "<<size[i]<<" son "<<son[i]
<<" top "<<top[i]<<" dfn "<<dfn[i]<<" pre"
<<pre[i]<<endl;
}
break;
}
}
return 0;
}
Input
1 2
1 4
2 5
2 6
1 3
4 8
4 9
4 10
6 11
6 12
3 7
9 13
13 14
-1 -1
Output
14
1 size 14 son 4 top 1 dfn 1 pre1
2 size 5 son 6 top 2 dfn 10 pre4
3 size 2 son 7 top 3 dfn 8 pre9
4 size 6 son 9 top 1 dfn 2 pre13
5 size 1 son 0 top 5 dfn 14 pre14
6 size 3 son 12 top 2 dfn 11 pre10
7 size 1 son 0 top 3 dfn 9 pre8
8 size 1 son 0 top 8 dfn 7 pre3
9 size 3 son 13 top 1 dfn 3 pre7
10 size 1 son 0 top 10 dfn 6 pre2
11 size 1 son 0 top 11 dfn 13 pre6
12 size 1 son 0 top 2 dfn 12 pre12
13 size 2 son 14 top 1 dfn 4 pre11
14 size 1 son 0 top 1 dfn 5 pre5