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: Time Limit Exceeded)

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int N;
vector<vector<int> > edge(200005);
map<pair<int, int>, ll> DP;
map<pair<int, int>, ll> child;
ll frac[200005];

ll solve(ll u, ll v) {
  if(DP[mp(u, v)]>0) return DP[mp(u, v)];
  DP[mp(u, v)] = frac[child[mp(u, v)]];
  ll h = mod - 2;
  ll shita = 1;
  ll tmpshita = 1;
  ll two;
  ll tmp;
  for(int i=0;i<edge[v].size();++i) {
    if(edge[v][i]==u) continue;
    DP[mp(u, v)] *= solve(v, edge[v][i]);
    DP[mp(u, v)] %= mod;
    tmpshita *= frac[1+child[mp(v, edge[v][i])]];
    tmpshita %= mod;
  }
  while(h>0) {
    tmp = tmpshita;
    two = 1;
    while(2*two<h) {
      two *= 2;
      tmp *= tmp;
      tmp %= mod;
    }
    h -= two;
    shita *= tmp;
    shita %= mod;
  }
  DP[mp(u, v)] *= shita;
  DP[mp(u, v)] %= mod;
  return DP[mp(u, v)];
}

ll getchild(int u, int v) {
  if(child[mp(u, v)]>0) return 1+child[mp(u, v)];
  for(int i=0;i<edge[v].size();++i) {
    if(edge[v][i]==u) continue;
    child[mp(u, v)] += getchild(v, edge[v][i]);
  }
  return 1+child[mp(u, v)];
}

int main() {
  frac[0] = 1;
  for(ll i=1;i<200005;++i) frac[i] = frac[i-1]*i%mod;
  cin>>N;
  int a, b;
  for(int i=0;i<N-1;++i) {
    cin>>a>>b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  for(int i=0;i<N;++i) {
    for(int j=0;j<edge[i].size();++j) {
      getchild(i, edge[i][j]);
    }
  }
  for(int i=0;i<N;++i) {
    for(int j=0;j<edge[i].size();++j) {
      if(DP[mp(i, edge[i][j])]>0) continue;
      solve(i, edge[i][j]);
    }
  }
  /**
  for(int i=0;i<N;++i) {
    for(int j=0;j<edge[i].size();++j) {
      cout<<i<<" "<<edge[i][j]<<" "<<DP[mp(i, edge[i][j])]<<endl;
    }
  }
  **/
  ll ans[N];
  ll shita;
  ll tmpshita;
  ll tmp;
  ll h;
  ll two;
  for(int i=0;i<N;++i) {
    ans[i] = frac[N-1];
    tmpshita = 1;
    for(int j=0;j<edge[i].size();++j) {
      tmpshita *= frac[1+child[mp(i, edge[i][j])]];
      tmpshita %= mod;
      ans[i] *= DP[mp(i, edge[i][j])];
      ans[i] %= mod;
    }
    h = mod - 2;
    shita = 1;
    while(h>0) {
      tmp = tmpshita;
      two = 1;
      while(2*two<h) {
        two *= 2;
        tmp *= tmp;
        tmp %= mod;
      }
      h -= two;
      shita *= tmp;
      shita %= mod;
    }
    ans[i] *= shita;
    ans[i] %= mod;
  }
  for(int i=0;i<N;++i) cout<<ans[i]<<endl;
}