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

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const M: i64 = 1_000_000_007;

fn modinv(mut x: i64, m: i64) -> i64 {
    let mut y = m;
    let mut u = 1;
    let mut v = 0;

    while y != 0 {
        let t = x / y;
        x -= t * y;
        u -= t * v;

        std::mem::swap(&mut x, &mut y);
        std::mem::swap(&mut u, &mut v);
    }

    (u + m) % m
}

#[derive(Debug, Clone)]
struct Edge {
    n: usize,
    s: i64,
    v: i64,
}

#[derive(Debug, Clone)]
struct Node {
    e: Vec<Edge>,
}

fn sumup(nodes: &mut [Node], idx: usize, src: usize, facts: &[i64], finvs: &[i64]) -> (i64, i64) {
    for i in 0..nodes[idx].e.len() {
        if nodes[idx].e[i].n != src && nodes[idx].e[i].v == 0 {
            let n = nodes[idx].e[i].n;
            let (s, v) = sumup(nodes, n, idx, facts, finvs);
            nodes[idx].e[i].s = s;
            nodes[idx].e[i].v = v;
        }
    }

    let mut size = 1i64;
    let mut value = 1i64;

    for e in &nodes[idx].e {
        if e.n != src {
            size += e.s;
            value = (value * finvs[e.s as usize]) % M;
            value = (value * e.v) % M;
        }
    }

    value = (value * facts[(size - 1) as usize]) % M;

    (size, value)
}

fn main() {
    let in_n: usize = read();
    let mut nodes = vec![Node { e: vec![] }; in_n];
    let mut facts = vec![1; in_n];
    let mut finvs = vec![1; in_n];

    for _ in 0..in_n - 1 {
        let mut a: usize = read();
        let mut b: usize = read();

        a -= 1;
        b -= 1;

        nodes[a].e.push(Edge { n: b, s: 0, v: 0 });
        nodes[b].e.push(Edge { n: a, s: 0, v: 0 });
    }

    for i in 2..in_n {
        facts[i] = (facts[i - 1] * i as i64) % M;
        finvs[i] = modinv(facts[i], M);
    }

    for i in 0..in_n {
        println! {"{}", sumup(&mut nodes, i, in_n, &facts, &finvs).1};
    }
}