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

use std::io::Read;
use std::collections::HashMap;

const MOD: usize = 1000000007;


fn mod_pow(v: usize, k: usize) -> usize {
    if k == 0 {
        return 1;
    }
    let mut ret = mod_pow(v * v % MOD, k / 2);
    if k % 2 == 1 {
        ret = ret * v % MOD;
    }
    return ret;
}

fn solve(mut memo: &mut HashMap<(usize, usize), (usize, usize)>, g: &Vec<Vec<usize>>, fac: &Vec<usize>, cur: usize, parent: usize) -> (usize, usize) {
    {
        let ans = memo.get(&(cur, parent));
        if ans.is_some() {
            return *ans.unwrap();
        }
    }
    let mut count = 1;
    let mut ans = 1;
    let mut div = 1;
    for &next in &g[cur] {
        if next == parent {
            continue;
        }
        let (child_count, child_ans) = solve(&mut memo, g, fac, next, cur);
        count += child_count;
        ans = ans * child_ans % MOD;
        div *= mod_pow(fac[child_count], MOD - 2);
    }
    ans = ans * div % MOD;
    ans = ans * fac[count - 1] % MOD;
    memo.insert((cur, parent), (count, ans));
    return (count, ans);
}

fn main() {
    let mut line = String::new();
    std::io::stdin().read_to_string(&mut line);
    let input: Vec<usize> = line.split_whitespace().map(|a| a.parse().unwrap()).collect();
    let n = input[0];
    let mut g: Vec<Vec<usize>> = Vec::new();
    let mut fac: Vec<usize> = vec![0; n + 1];
    fac[0] = 1;
    for i in 1 .. fac.len() {
        fac[i] = fac[i - 1] * i % MOD;
    }
    g.resize(n, Vec::new());
    for i in 0..n - 1 {
        let (a, b) = (input[i * 2 + 1] - 1, input[i * 2 + 2] - 1);
        g[a].push(b);
        g[b].push(a);
    }


    let mut memo: HashMap<(usize, usize), (usize, usize)> = HashMap::new();

    for i in 0..n {
        let (_, ans ) = solve( &mut memo, &g, &fac, i, n);
        println!("{}", ans);
    }
}