##
sub f {
$h{$_}||=[]for map@$_,%h=@_;
sub x {
my$x=1;
$x+=x($_)for@{@h{@_}||[]};
$x
}
sort{x($a)<=>x$b}keys%h
}
####
@h{@$_}=@h{@$_}for%h=@_;
####
$x+=x($_)for@{@h{@_}||0};
####
sub x {
1,map{x($_)}@{@h{@_}||0}
}
####
@h{@$_}=@h{@$_}for%h=@_;sub x{1,map{x($_)}@{@h{@_}||0}}sort{x($a)<=>x$b}keys%h