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: Runtime Error)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll MAX_N = 200000;
const ll MOD = 1000000007;

class Prod {
public:
	vector<ll> K_;
	vector<ll> invK_;
	vector<ll> invN_;
	Prod() {
		K_.assign(MAX_N, 1);
		invK_.assign(MAX_N, 1);
		invN_.assign(MAX_N, 1);
		for (ll i = 2; i < MAX_N; i++) {
			K_.at(i) = (K_.at(i - 1) * i) % MOD;
			invN_.at(i) = MOD - ((invN_.at(MOD % i) * (MOD / i)) % MOD);
			invK_.at(i) = (invK_.at(i - 1) * invN_.at(i)) % MOD;
//			cout << "(" << i << "," << K_.at(i) << "," << invN_.at(i) << "," << invK_.at(i) << ")" << endl;
		}
	}
	ll kaijo(ll v) { return(K_.at(v)); }
	ll inv(ll v) { return(invN_.at(v)); }
	ll invKaijo(ll v) { return(invK_.at(v)); }
	ll comb(ll v, ll w) { return((K_.at(v) * invK_.at(w) % MOD) * invK_.at(v - w) % MOD); }
	ll combinv(ll v, ll w) { return((invK_.at(v) * K_.at(w) % MOD) * K_.at(v - w) % MOD); }
};

Prod p;

class Node {
public:
	ll id_;
	pair<ll, ll> all;
	map<Node*, pair< ll, ll> > f_; // first から入ってきたら、このノードの(個数,dp) ＝ (second.(first, second)
	void printLink() {
		for (auto it = f_.begin(); it != f_.end(); it++) {
			cout << "Link " << id_ << " to " << it->first->id_ << endl;
		}
	};
	void insertLink(Node* l) { f_[l].first = 0; f_[l].second = 0; }
	pair<ll,ll> getDp(Node* prev) { // (house_,dp_)
//		cout << "    counthouse " << id_ << endl;
		if(prev != nullptr){
			if (f_[prev].second > 0) { return(f_[prev]); } // dpが計算済み
			if (all.second > 0) { // allが計算済み
				pair<ll, ll> rev = prev->getDp(this);
				ll mydp = (all.second * p.inv(rev.second) % MOD) * p.combinv(all.first - 1, rev.first) % MOD;
				return(pair<ll,ll>(all.first - rev.first, mydp));
			}
		}

		// dp計算未済み
		ll count = 0;
		ll prod = 1;
		for (auto it = f_.begin(); it != f_.end(); it++) {
			if (it->first != prev) {
				pair<ll, ll> next = it->first->getDp(this);
				count += next.first;
				prod = (prod * next.second % MOD) * p.invKaijo(next.first) % MOD;
			}
		}
		ll mydp = (prod * p.kaijo(count)) % MOD;
//		if(prev != nullptr){
//			cout << "    " << prev->id_ << " to " << id_ << ", house_ = " << count + 1 << ", dp = " << prod << endl;
//		}
//		else {
//			cout << "    " << "0" << " to " << id_ << ", house_ = " << count + 1 << ", dp = " << prod << endl;
//		}
		if (prev != nullptr) {
			f_[prev] = pair<ll, ll>(count + 1, mydp);
			if(all.second == 0){ // allの計算がまだなので、計算する。
				pair<ll, ll> v = prev->getDp(this);
				prod = (prod * v.second % MOD) * p.invKaijo(v.first) % MOD; // dp(c)/nc! を全部掛けた
				ll allCount = count + v.first;
				ll alldp = (prod * p.kaijo(allCount)) % MOD;
				all = pair<ll, ll>(allCount + 1, alldp);
			}
		}
		return(pair<ll, ll>(count + 1, mydp));
	};
};


int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);


	ll N;
	cin >> N;
	Node* nodes = new Node[N];
	for (int i = 0; i < N; i++) {
		nodes[i].id_ = i + 1;
		nodes[i].all = pair<ll, ll>(0, 0);
	}
	for (int i = 1; i <= N - 1; i++) {
		int ai, bi;
		cin >> ai >> bi;
		nodes[ai - 1].insertLink(&(nodes[bi - 1]));
		nodes[bi - 1].insertLink(&(nodes[ai - 1]));
	}

//	for (ll i = 0; i < N; i++) {nodes[i].printLink();}cout << "end printlink" << endl;


	for (ll i = 0; i < N; i++) {
//		cout << "start " << i << endl;
		pair<ll,ll> ret = nodes[i].getDp(nullptr);
		cout << ret.second << endl;
	}
//	cout << "END" << endl;
}