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++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VL vector<long long>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1000000007;
const int SIZE = 2e5+10;
VI e[SIZE];
void ADD(LL& x,LL v){
    x=(x+v)%MOD;
}
LL fac[SIZE],inv[SIZE];
LL mypow(LL x,LL y){
    LL res=1;
    while(y){
        if(y&1)res=res*x%MOD;
        y>>=1;
        x=x*x%MOD;
    }
    return res;
}
LL C(int x,int y){
    if(y<0||y>x)return 0;
    return fac[x]*inv[y]%MOD*inv[x-y]%MOD;
}
void build(){
    assert(MOD>=SIZE);
    fac[0]=1;
    REPP(i,1,SIZE)fac[i]=fac[i-1]*i%MOD;
    inv[SIZE-1]=mypow(fac[SIZE-1],MOD-2);
    for(int i=SIZE-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%MOD;
}
LL BIT[SIZE];
void ins(int x,LL v){
    for(;x;x-=x&-x)BIT[x]=BIT[x]*v%MOD;
}
LL qq(int x){
    LL res=1;
    for(;x<SIZE;x+=x&-x)res=res*BIT[x]%MOD;
    return res;
}
int ll[SIZE],rr[SIZE],id,N;
LL INV(int x){return mypow(x,MOD-2);}
void dfs0(int x,int lt){
    ll[x]=rr[x]=++id;
    REP(i,SZ(e[x])){
        int y=e[x][i];
        if(y==lt)continue;
        dfs0(y,x);
        rr[x]=rr[y];
    }
}
int dfs(int x,int lt){
    int num=1;
    LL me_inv=1;
    VI sons;
    REP(i,SZ(e[x])){
        int y=e[x][i];
        sons.PB(0);
        if(y==lt)continue;
        int res=dfs(y,x);
        sons[i]=res;
        num+=res;
        me_inv=me_inv*inv[res]%MOD;
    }
    LL v=me_inv*inv[N-num]%MOD*fac[N-1]%MOD;
    ins(ll[x],v);
    ins(ll[x]-1,INV(v));
    v=me_inv*fac[num-1]%MOD;
    ins(N,v);
    ins(rr[x],INV(v));
    ins(ll[x]-1,v);
    REP(i,SZ(e[x])){
        int y=e[x][i];
        if(y==lt)continue;
        v=me_inv*fac[sons[i]]%MOD*inv[N-num]%MOD*fac[N-sons[i]-1]%MOD;
        ins(rr[y],v);
        ins(ll[y]-1,INV(v));
    }
    return num;
}
int main(){
    REP(i,SIZE)BIT[i]=1;
    build();
    RI(N);
    REPP(i,1,N){
        DRII(x,y);
        e[x].PB(y);
        e[y].PB(x);
    }
    dfs0(1,1);
    dfs(1,1);
    REPP(i,1,N+1){
        printf("%lld\n",qq(i));
    }
    return 0;
}