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 (GCC 9.2.1) (judge verdict: Runtime Error)

#include <stdio.h>

#define Mod 1000000007

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

typedef struct List {
	struct List *next;
	int v, size, id;
	long long count;
} list;

list *adj[200001] = {}, e[400001];
long long fact[200001], fact_inv[200001];

long long recursion(int k)
{
	if (e[k^1].count > 0) return e[k^1].count;
	else e[k^1].count = 1;
	
	int u = e[k].v, w = e[k^1].v, tmp;
	list *p;
	for (p = adj[u]; p != NULL; p = p->next) {
		if (p->v == w) continue;
		recursion(p->id);
		e[k^1].size += e[(p->id)^1].size;
	}
	for (p = adj[u], tmp = e[k^1].size; p != NULL; p = p->next) {
		if (p->v == w) continue;
		e[k^1].count = e[k^1].count * e[(p->id)^1].count % Mod * fact[tmp] % Mod * fact_inv[e[(p->id)^1].size] % Mod * fact_inv[tmp - e[(p->id)^1].size] % Mod;
		tmp -= e[(p->id)^1].size;
	}
	e[k^1].size++;
	return e[k^1].count;
}

int main()
{
	int i, N, u, w;
	scanf("%d", &N);
	for (i = 0; i < N - 1; i++) {
		scanf("%d %d", &u, &w);
		e[i*2].v = w;
		e[i*2+1].v = u;
		e[i*2].count = 0;
		e[i*2+1].count = 0;
		e[i*2].size = 0;
		e[i*2+1].size = 0;
		e[i*2].id = i * 2;
		e[i*2+1].id = i * 2 + 1;
		e[i*2].next = adj[u];
		e[i*2+1].next = adj[w];
		adj[u] = &(e[i*2]);
		adj[w] = &(e[i*2+1]);
	}
	
	int flag[200001] = {}, q[200001], head, tail;
	long long ans[200001], tmp;
	list *p;
	for (i = 1, fact[0] = 1; i <= N; i++) fact[i] = fact[i-1] * i % Mod;
	for (i = N - 1, fact_inv[N] = div_mod(1, fact[N], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;
	for (head = 0, tail = 1, q[0] = 1, flag[1] = 1; head < tail; head++) {
		u = q[head];
		for (p = adj[u], ans[u] = 1, tmp = N - 1; p != NULL; p = p->next) {
			ans[u] = ans[u] * recursion(p->id) % Mod * fact[tmp] % Mod * fact_inv[e[(p->id)^1].size] % Mod * fact_inv[tmp - e[(p->id)^1].size] % Mod;
			tmp -= e[(p->id)^1].size;
			if (flag[p->v] == 0) {
				flag[p->v] = 1;
				q[tail++] = p->v;
			}
		}
		for (p = adj[u]; p != NULL; p = p->next) {
			if (p->count == 0) {
				p->count = div_mod(ans[u], e[(p->id)^1].count * fact[N-1] % Mod * fact_inv[e[(p->id)^1].size] % Mod * fact_inv[N-1-e[(p->id)^1].size], Mod);
				p->size = N - e[(p->id)^1].size;
			}
		}
	}
	for (i = 1; i <= N; i++) printf("%lld\n", ans[i]);
	fflush(stdout);
	return 0;
}