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: Accepted)

//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

ll facts[200010],invs[200010];
ll dp[200010], ret[200010], ni[200010];
ll powll(ll base,ll power){
    ll ans = 1;
    while (power){
        if (power&1) ans = (base*ans)%mod;
        base = (base*base)%mod;
        power >>= 1;
    }
    return ans;
}

void merge(int i, int k){
    ni[i] += ni[k];
    dp[i] = dp[i] * dp[k] % mod * 
            facts[ni[i]] % mod * 
            invs[ni[k]] % mod * 
            invs[ni[i]-ni[k]] % mod;
}
void invmerge(int i, int k){
    dp[i] = dp[i] * powll(dp[k], mod-2) % mod *
            invs[ni[i]] % mod *
            facts[ni[k]] % mod *
            facts[ni[i]-ni[k]] % mod;
    ni[i] -= ni[k];
}

int n,a,b;
vvi tree;
void dfs1(int i){
    dp[i] = 1;
    for(auto ch: tree[i]) {
        if (dp[ch]) continue;
        dfs1(ch);
        merge(i, ch);
    }
    ni[i]++;
}
void dfs2(int i){
    ret[i] = dp[i];
    ni[i]--;
    for(auto ch: tree[i]){
        if (ret[ch]) continue;
        invmerge(i, ch);
        ni[ch]--;
        ni[i]++;
        merge(ch, i);
        ni[ch]++;
        dfs2(ch);
        ni[ch]--;
        invmerge(ch, i);
        ni[ch]++;
        ni[i]--;
        merge(i, ch);
    }
    ni[i]++;
}

signed main(){
    ll f = 1;
    n = 200001;
    facts[0] = 1;
    FOR(i,1,n+1){
        f *= i;
        f %= mod;
        facts[i] = f;
    }
    ll inv = powll(f,mod-2);
    invs[n] = inv;
    REPNS(i,n){
        inv *= i;
        inv %= mod;
        invs[i-1] = inv;
    }

    I(n);
    tree.resize(n);
    REP(i,n-1){
        I(a); I(b);
        a--; b--;
        tree[a].pb(b);
        tree[b].pb(a);
    }
    dfs1(0);
    dfs2(0);
    REP(i,n) printf("%lld\n", ret[i]);
}