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 maxn 200005
#define MOD 1000000007
#define INF 10000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

ll n;
vector<ll> v[maxn];
ll dp[maxn], dp2[maxn], child[maxn], ans[maxn];
ll f[maxn], finv[maxn];

ll power(ll a, ll b){
    if(b==0) return 1;
    ll r = power(a, b/2);
    r = (r*r)%MOD;
    if(b%2) r = (r*a)%MOD;
    return r;
}

ll inv(ll x){ return power(x, MOD-2); }

void pre(){
    f[0] = finv[0] = 1;
    for(ll i = 1; i < maxn; i++){
        f[i] = (f[i-1]*i)%MOD; //cout << f[i] << " ";
        finv[i] = (finv[i-1]*(power(i, MOD-2))%MOD);
    }
}

ll dfs(ll u, ll p){
    ll c = 1, tmp  = 1;
    for(auto x: v[u]){
        if(x!=p){
            ll sizeu = dfs(x, u);
            c += sizeu;
            tmp = (tmp * dp[x])%MOD;
            tmp = (tmp * finv[sizeu])%MOD;
        }
    }
    tmp = (tmp * f[c-1])%MOD;
    dp[u] = tmp; child[u] = c;
    return c;
}

void dfs2(ll u, ll p){
    for(auto x: v[u]){
        if(x!=p){
            /*ll du = (ans[u] * (f[child[x]] * inv(dp[x]))%MOD)%MOD;
            du = (du * (f[n-1-child[x]] * finv[n-1])%MOD)%MOD;
            ans[x] = (dp[x] * (finv[child[x]-1]*f[n-1])%MOD)%MOD;
            ans[x] = (ans[x] * (du * finv[n-1-child[x]])%MOD)%MOD;*/

            ans[x] = (ans[u] * (child[x] *inv(n-child[x]))%MOD)%MOD;
            dfs2(x, u);
        }
    }
}

void solve(){
    cin >> n;
    for(ll i = 0; i < n-1; i++){
        ll x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1, 0);
    ans[1] = dp[1];
    dfs2(1, 0);
    for(ll i = 1; i <= n; i++){
        cout << ans[i] << " ";
    }

}

int main()
{
    fast(); //power(2, 11);
    int t= 1; //cin >> t;
    while(t--){
        pre();
        solve();
    }
}

/*
5
1 2
2 3
3 4
3 5
*/