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 5.4.1) (judge verdict: Wrong Answer)

#include <float.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}
int compr(const void *a, const void *b){return *(int*)b-*(int*)a;}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

inline int max2(const int a, const int b){return a>b?a:b;}
inline int min2(const int a, const int b){return a>b?b:a;}
inline int dif2(const int a, const int b){return a>b?a-b:b-a;}

int k[200001];
int rk[200001];
//int r[200001];

int getk(int a, int x){
	if(x==1) return a;
	int b = getk(a, x/2);
	b = ((long)b)*b%P;
	if((x&1)==0){
		return b;
	}else{
		return ((long)b)*a%P;
	}
}
 
int comb(int a, int b){
	if(a<b) return 0;
	return ((long)k[a])*rk[b]%P*rk[a-b]%P;
}
int combr(int a, int b){
	if(a<b) return 0;
	return ((long)rk[a])*k[b]%P*k[a-b]%P;
}

void init(int n){
	//r[1]=1;
	//for(int i=2; i<=n; i++){
	//	r[i]=P-((long)P/i*r[P%i])%P;
	//}
	k[0]=1;
	for(int i=1; i<=n; i++){
		k[i]=k[i-1]*((long)i)%P;
	}	
	rk[n]=getk(k[n], P-2);
	for(int i=n-1; i>=0; i--){
		rk[i]=((long)rk[i+1])*(i+1)%P;
	}
}

int edge[199999][2];

int qmem[499996];

int *e[200000];
int el[200000];

int s[200000];
int rs[200000];
int is[200000];
int par[200000];

int d[200000][6];

int main(void){
	int n=nextpint();
	init(n);
	for(int i=0; i<n-1; i++){
		int A=nextpint()-1;
		int B=nextpint()-1;
		edge[i][0]=A;
		edge[i][1]=B;
		el[A]++;
		el[B]++;
	}
	int ne=0;
	for(int i=0; i<n; i++){
		e[i]=&qmem[ne];
		ne+=el[i];
		el[i]=0;
	}
	for(int i=0; i<n-1; i++){
		int A=edge[i][0];
		int B=edge[i][1];
		e[A][el[A]++]=B;
		e[B][el[B]++]=A;
	}
	s[0]=0;
	rs[0]=0;
	is[0]=1;
	int S=1;
	for(int i=0; i<n; i++){
		for(int j=0; j<el[s[i]]; j++){
			int p=e[s[i]][j];
			if(is[p]==0){
				s[S]=p;
				rs[p]=S;
				S++;
				par[p]=s[i];
				is[p]=1;
			}
		}
	}
	for(int i=n-1; i>=0; i--){
		int p=s[i];
		if(el[p]==0){
			d[p][0]=1;
			d[p][1]=1;
		}else{
			int w=0;
			int h=0;
			for(int j=0; j<el[p]; j++){
				if(rs[e[p][j]]>i){
					w++;
					h+=d[e[p][j]][1];
				}
			}
			d[p][0]=w;
			d[p][1]=h+1;
			long now=1;
			long nowr=1;
			for(int j=0; j<el[p]; j++){
				int q=e[p][j];
				if(rs[q]>i){
					now=(now*d[q][2])%P;
					now=(now*comb(h, d[q][1]))%P;
					nowr=(nowr*d[q][3])%P;
					nowr=(nowr*combr(h, d[q][1]))%P;
					h-=d[q][1];
				}
			}
			d[p][2]=now;
			d[p][3]=nowr;
		}
	}
	d[0][4]=d[0][2];
	printf("%d\n", d[0][2]);
	for(int i=1; i<n; i++){
		int p=s[i];
		int h=d[p][1];
		long now=d[par[p]][4];
		now=(now*combr(n-1, d[p][1]))%P;
		now=(now*d[p][3])%P;
		now=(now*comb(n-1, n-h));
		h--;
		for(int j=0; j<el[p]; j++){
			int q=e[p][j];
			if(rs[q]>i){
				now=(now*d[q][2])%P;
				now=(now*comb(h, d[q][1]))%P;
				h-=d[q][1];
			}
		}
		d[p][4]=now;
		printf("%d\n", (int)now);
	}
}