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>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define TEST(...)                                                              \
    { printf("! "), printf(__VA_ARGS__); }
#else
#define TEST(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 1e9 + 7;
class {
  public:
    int n;
    vector<int> V[maxn];
    i64 d[maxn], sz[maxn], fa[maxn], ans[maxn], szfa[maxn];
    i64 inv[maxn], fac[maxn], invfa[maxn];
    void solve() {
        fac[0] = 1;
        invfa[0] = 1;
        inv[1] = 1;
        for (int i = 2; i < maxn; ++i)
            inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
        for (int i = 1; i < maxn; ++i) {
            fac[i] = fac[i - 1] * i % MOD;
            invfa[i] = invfa[i - 1] * inv[i] % MOD;
        }
        cin >> n;
        for (int i = 1; i < n; ++i) {
            int u, v;
            cin >> u >> v;
            V[u].push_back(v);
            V[v].push_back(u);
        }
        dfs(1, -1);
        dfs2(1, -1);
        for (int i = 1; i <= n; ++i) {
            cout << ans[i] << '\n';
        }
    }
    void dfs(int u, int f) {
        sz[u] = 1;
        d[u] = 1;
        for (int v : V[u]) {
            if (v != f) {
                dfs(v, u);
                sz[u] += sz[v];
                (d[u] *= d[v] * invfa[sz[v]]) %= MOD;
            }
        }
        (d[u] *= fac[sz[u] - 1]) %= MOD;
    }

    void dfs2(int u, int f) {
        if (u == 1) {
            fa[1] = 1;
            szfa[1] = 0;
            ans[u] = d[u];
        } else {
            fa[u] = d[f] * fac[sz[u]] % MOD * fac[n - sz[u] - 1] % MOD * fa[f] %
                    MOD;
            (fa[u] *= invfa[sz[f] - 1] * pw(d[u], MOD - 2) % MOD *
                      invfa[szfa[f]] % MOD) %= MOD;
            szfa[u] = n - sz[u];
            ans[u] = fac[n - 1] * d[u] % MOD * fa[u] % MOD * invfa[sz[u] - 1] %
                     MOD * invfa[szfa[u]] % MOD;
        }
        for (int v : V[u]) {
            if (v != f) {
                dfs2(v, u);
            }
        }
    }
    i64 pw(i64 a, i64 b) {
        i64 res = 1;
        while (b) {
            if (b & 1ll)
                res = res * a % MOD;
            a = a * a % MOD;
            b >>= 1;
        }
        return res;
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}