Problem:
Score : 600 points

Problem Statement

We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i.
For each k=1, ..., N, solve the problem below:

Consider writing a number on each vertex in the tree in the following manner:

First, write 1 on Vertex k.

Then, for each of the numbers 2, ..., N in this order, write the number on the vertex chosen as follows:

Choose a vertex that still does not have a number written on it and is adjacent to a vertex with a number already written on it. If there are multiple such vertices, choose one of them at random.

Find the number of ways in which we can write the numbers on the vertices, modulo (10^9+7).

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq a_i,b_i \leq N

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}

Output

For each k=1, 2, ..., N in this order, print a line containing the answer to the problem.

Sample Input 1

3
1 2
1 3

Sample Output 1

2
1
1

The graph in this input is as follows:

For k=1, there are two ways in which we can write the numbers on the vertices, as follows:

Writing 1, 2, 3 on Vertex 1, 2, 3, respectively

Writing 1, 3, 2 on Vertex 1, 2, 3, respectively

Sample Input 2

2
1 2

Sample Output 2

1
1

The graph in this input is as follows:

Sample Input 3

5
1 2
2 3
3 4
3 5

Sample Output 3

2
8
12
3
3

The graph in this input is as follows:

Sample Input 4

8
1 2
2 3
3 4
3 5
3 6
6 7
6 8

Sample Output 4

40
280
840
120
120
504
72
72

The graph in this input is as follows:

Solution in C (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<stdio.h>
int ta[200010],nt[400010],to[400010],cc[400010];
long long u[200010],ANS[200020],ans[200020];
int mbk(long long a,int n,int m){return n?(mbk((a*a)%m,n/2,m)*(n%2?a:1))%m:1;}
int inv(int a,int m){return mbk((long long)a,m-2,m);}
long long pp[200010],M=1e9+7;
void fc(int s,int t){ans[s]=ans[s]*ans[t]%M;}
void ic(int s,int t){ans[s]=ans[s]*inv(ans[t],M);}
void fp(int s){ans[s]=ans[s]*inv(cc[s],M)%M;}
void ip(int s){ans[s]=ans[s]*cc[s]%M;}
void f(int s){//printf("!%d\n",s);
  long long i;
  u[s]=1;
  for(i=ta[s];i+1;i=nt[i]){
    if(u[to[i]])continue;
    f(to[i]);
    fc(s,to[i]);
    cc[s]+=cc[to[i]];
  }
  fp(s);
}

void h(int s,int t){
  ip(s);
  ic(s,t);
  ip(t);
  cc[s]-=cc[t];
  cc[t]+=cc[s];
  fp(s);
  fc(t,s);
  fp(t);
}
void g(int s){//printf("!!%d %d\n",s,cc[s]);
  int i;
  u[s]=2;
  ANS[s]=ans[s];
  for(i=ta[s];i+1;i=nt[i]){
    if(u[to[i]]==2)continue;
    //printf("%d %d %d %d %lld %lld\n",s,to[i],cc[s],cc[to[i]],ans[s],ans[to[i]]);
    h(s,to[i]);
    //printf("%d %d %d %d %lld %lld\n",s,to[i],cc[s],cc[to[i]],ans[s],ans[to[i]]);
    g(to[i]);
    h(to[i],s);
  }
}
int main(){
  int n,a,b,i;
  scanf("%d",&n);
  for(i=0;i<=n;i++)ta[i]=-1;
  pp[0]=1;
  for(i=1;i<=n;i++)pp[i]=(pp[i-1]*i)%M;
  //for(i=0;i<=n;i++)ip[i]=inv(i,M);
  for(i=1;i<=n;i++)ans[i]=cc[i]=1;
  for(i=0;i<n-1;i++){
    scanf("%d %d",&a,&b);
    nt[i    ]=ta[to[i+n-1]=a];
    nt[i+n-1]=ta[to[i    ]=b];
    ta[b]=i+n-1;
    ta[a]=i;
  }
  f(1);
  //for(i=0;i<=10;i++)printf("%lld\n",pp[i]);printf("\n");
  //for(i=0;i<=n;i++)printf("%d\n",cc[i]);
  //printf("%d\n",f(1));
  //for(i=0;i<=n;i++)printf("%d\n",cc[i]);
  //for(i=1;i<=n;i++)printf("%3d ",i);printf("\n");
  //for(i=1;i<=n;i++)printf("%3lld ",ans[i]);printf("\n");
  //for(i=1;i<=n;i++)printf("%3d ",cc[i]);printf("\n");
  g(1);
  for(i=1;i<=n;i++)printf("%lld\n",ANS[i]*pp[n]%M);
  return 0;
}