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)

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

const int maxn = 2e5 + 5;
const int64 md = 1e9 + 7;
int n;
vector <int> e[maxn];
int64 f[maxn], cnt[maxn], res[maxn], fac[maxn], p[maxn];

void input(){
    cin >> n;
    int u, v;
    for (int i = 1; i < n; i++){
        cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
}

int64 pw(int64 a, int64 b){
    if (b == 0) return 1;
    int64 tmp = pw(a, b / 2);
    tmp = (tmp * tmp) % md;
    if (b % 2) tmp = (tmp * a) % md;
    return tmp;
}

int64 calcC(int n, int k){
    return (((fac[n] * pw(fac[n - k], md - 2)) % md) * pw(fac[k], md - 2)) % md;
}

void dfs1(int u){
    for (int v : e[u])
    if (v != p[u]){
        p[v] = u;
        dfs1(v);
        cnt[u] += cnt[v];
    }
    int tmp = cnt[u];
    f[u] = 1;
    for (int v : e[u])
    if (v != p[u]){
        f[u] = (((f[u] * calcC(tmp, cnt[v])) % md) * f[v]) % md;
        tmp -= cnt[v];
    }
    cnt[u]++;
}

void dfs2(int u, int64 curf){
    res[u] = (((curf * calcC(n - 1, n - cnt[u])) % md) * f[u]) % md;
    for (int v : e[u])
    if (v != p[u]){
        int64 tmp = (res[u] * pw(calcC(n - 1, cnt[v]), md - 2)) % md;
        tmp = (tmp * pw(f[v], md - 2)) % md;
        dfs2(v, tmp);
    }
}

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    input();
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % md;
    dfs1(1);
    dfs2(1, 1);
    for (int i = 1; i <= n; i++) cout << res[i] << endl;
    return 0;
}