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 <bits/stdc++.h>
using namespace std;
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0) return 1;
	else if(N % 2 == 0) return power(MOD(a * a), N / 2);
	else return MOD(a * power(a, N - 1));
}

int inverse(int a){
	return power(a, p - 2);
}

int fact(int N){
	static vector<int> _fact(1, 1);
	for(int i = _fact.size(); i <= N; i++){
		_fact.push_back(MOD(i * _fact[i - 1]));
	}
	return _fact[N];
}
 
int fact_inv(int N){
	static vector<int> inv(2, 1), _fact_inv(2, 1);
	for(int i = inv.size(); i <= N; i++){
		inv.push_back(MOD(-(p / i) * inv[p % i]));
		_fact_inv.push_back(MOD(inv[i] * _fact_inv[i - 1]));
	}
	return _fact_inv[N];
}
 
int combination(int N, int k){
	if(k < 0 || N < k || N < 0) return 0;
	else return MOD(fact(N) * MOD(fact_inv(N - k) * fact_inv(k)));
}

int N;
vector<vector<int>> t;
vector<int> x, n, xs, n_facts, y, ans;

void dfs(int u, int parent){
	xs[u] = 1;
	n_facts[u] = 1;
	n[u] = 1;
	for(int i = 0; i < t[u].size(); i++){
		if(t[u][i] != parent){
			dfs(t[u][i], u);
			xs[u] = MOD(xs[u] * x[t[u][i]]);
			n_facts[u] = MOD(n_facts[u] * fact(n[t[u][i]]));
			n[u] += n[t[u][i]];
		}
	}
	x[u] = MOD(MOD(fact(n[u] - 1) * inverse(n_facts[u])) * xs[u]);
}

void dfs2(int u, int parent){
	ans[u] = MOD(MOD(y[u] * xs[u]) * MOD(fact(N - 1) * inverse(MOD(n_facts[u] * fact(N - n[u])))));
	for(int i = 0; i < t[u].size(); i++){
		if(t[u][i] != parent){
			y[t[u][i]] = MOD(MOD(MOD(ans[u] * MOD(fact(n[t[u][i]]) * fact(N - 1 - n[t[u][i]]))) * inverse(MOD(x[t[u][i]] * fact(N - 1)))));
			dfs2(t[u][i], u);
		}
	}
}

signed main(){
	scanf("%lld", &N);
	t.assign(N, vector<int>(0));
	for(int i = 1; i < N; i++){
		int a, b;
		scanf("%lld%lld", &a, &b);
		a--;
		b--;
		t[a].push_back(b);
		t[b].push_back(a);
	}
	x.assign(N, 0);
	n.assign(N, 0);
	xs.assign(N, 0);
	n_facts.assign(N, 0);
	dfs(0, -1);
	ans.assign(N, 0);
	y.assign(N, 1);
	dfs2(0, -1);
	for(int i = 0; i < N; i++){
		printf("%lld\n", ans[i]);
	}
	return 0;
}