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: Accepted)

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};
use std::collections::HashMap;

fn main() {
    input!{
        n: usize,
        v: [(usize1, usize1); n - 1]
    }
    let mut t = vec![vec![]; n];
    for &(a, b) in &v {
        t[a].push(b);
        t[b].push(a);
    }
    let d = 1000000007;
    let mut st = vec![1; n + 1];
    for i in 1..n {
        st[i] = st[i - 1] * i % d;
    }
    let sti: Vec<usize> = st.iter().map(|&x| inv_m(x, d)).collect();
    let mut np = HashMap::new();
    dfs1(0, 0, &t, &mut np, &st, &sti, d);
    println!("{}", np.get(&(0, 0)).unwrap().1);
    for &v in &t[0] {
        dfs2(v, 0, &t, &mut np, &st, &sti, d);
    }
    for i in 1..n {
        println!("{}", np.get(&(i, i)).unwrap().1);
    }
}

fn dfs1(v: usize, r: usize, t: &Vec<Vec<usize>>, np: &mut HashMap<(usize, usize), (usize, usize)>, st: &Vec<usize>, sti: &Vec<usize>, d: usize) {
    let mut n = 1;
    let mut p = 1;
    for &c in &t[v] {
        if c == r {
            continue;
        }
        dfs1(c, v, t, np, st, sti, d);
        let (ni, pi) = *np.get(&(v, c)).unwrap();
        n += ni;
        p = p * pi % d * sti[ni] % d;
    }
    p = p * st[n - 1] % d;
    np.insert((r, v), (n, p));
}

fn dfs2(v: usize, r: usize, t: &Vec<Vec<usize>>, np: &mut HashMap<(usize, usize), (usize, usize)>, st: &Vec<usize>, sti: &Vec<usize>, d: usize) {
    let (nr, pr) = *np.get(&(r, r)).unwrap();
    let (nv, pv) = *np.get(&(r, v)).unwrap();
    let n1 = nr - nv;
    let p1 = pr * st[nr - nv - 1] % d * sti[nr - 1] % d * st[nv] % d * inv_m(pv, d) % d;
    np.insert((v, r), (n1, p1));
    np.insert((v, v), (nv + n1, pv * sti[nv - 1] % d * st[nv - 1 + n1] % d * sti[n1] % d * p1 % d));
    for &c in &t[v] {
        if c == r {
            continue;
        }
        dfs2(c, v, t, np, st, sti, d);
    }
}

fn pow_m(n: usize, mut p: usize, d: usize) -> usize {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % d;
            p /= 2;
        } else {
            ret = ret * r % d;
            p -= 1;
        }
    }
    ret
}

fn inv_m(n: usize, d: usize) -> usize {
    pow_m(n, d - 2, d)
}