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;
typedef long long ll;
#define p(a) printf("%lld\n",a);
ll n;
const ll mod=1e9+7;
vector<ll> g[200005];
bool used[200005]={0};
ll size[200005]={0};
ll njie[200005]={0};
ll nfan[200005]={0};
ll sum[200005]={0};
ll a[200005]={0};
ll qpow(ll a,ll b)
{
	if(b==0) return 1;
	else if(b==1) return a;
	ll c=qpow(a,b/2);
	if(b%2==0) return c*c%mod;
	else return c*c%mod*a%mod;
}
void dfs1(ll u)
{	//printf("%lld ",u);
	used[u]=true;
	for(ll i=0;i<g[u].size();i++)
	{
		ll v=g[u][i];
		if(used[v]) continue;
		dfs1(v);
		size[u]+=size[v];
		a[u]=a[u]*a[v]%mod*nfan[size[v]]%mod;
	}
	a[u]=a[u]*njie[size[u]-1]%mod;
}
void change(ll u,ll v)
{
	a[u]=a[u]*nfan[size[u]-1]%mod;
	a[u]=a[u]*njie[size[u]-size[v]-1]%mod;
	a[u]=a[u]*njie[size[v]]%mod;
	a[u]=a[u]*qpow(a[v],mod-2)%mod;
	size[u]=size[u]-size[v];
	a[v]=a[v]*nfan[size[v]-1]%mod;
	size[v]=size[v]+size[u];
	a[v]=a[v]*njie[size[v]-1]%mod;
	a[v]=a[v]*a[u]%mod;
	a[v]=a[v]*nfan[size[u]]%mod;
}
void dfs2(ll u)
{
	sum[u]=a[u];
	used[u]=true;
	for(ll i=0;i<g[u].size();i++)
	{
		ll v=g[u][i];
		if(!used[v])
		{
			change(u,v);
			dfs2(v);
			change(v,u);
		}
	}
}
int main()
{
	scanf("%lld",&n);
	njie[0]=1;
	for(ll i=1;i<=n;i++) njie[i]=njie[i-1]*i%mod,a[i]=1,size[i]=1;
	nfan[n]=qpow(njie[n],mod-2);
	for(ll i=n-1;i>0;i--) nfan[i]=nfan[i+1]*(i+1)%mod;
	nfan[0]=nfan[1];
	for(ll i=0;i<n-1;i++)
	{
		ll u,v;
		scanf("%lld%lld",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs1(1);
	memset(used,0,sizeof(used));
	dfs2(1);
	for(ll i=1;i<=n;i++)
	{
		printf("%lld ",sum[i]);
	}
}