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)

#![allow(dead_code)]

use std::io::{stdin, Read};
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};

pub fn get_factorials(n: usize) -> Vec<Mint<usize>> {
    let mut facts = vec![Mint(0); n];
    facts[0] = Mint(1);
    for i in 1..n {
        facts[i] = facts[i - 1] * (i as usize);
    }
    facts
}

pub fn get_facinvs(n: usize, facts: &Vec<Mint<usize>>) -> Vec<Mint<usize>> {
    let mut invs = vec![Mint(0); n];
    invs[n - 1] = facts[n - 1].inv();
    for i in (0..(n - 1)).rev() {
        invs[i] = invs[i + 1] * (i + 1)
    }
    invs
}

fn gcd(a: usize, b: usize) -> usize {
    match b {
        0 => a,
        _ => gcd(b, a % b),
    }
}

fn prime_factors(x: usize) -> Vec<usize> {
    let mut res = vec![];
    let mut y = x;
    let mut p = 2;
    let upper = (y as f64).sqrt() as usize;
    while y > 1 && p <= upper {
        match y % p {
            0 => {
                res.push(p);
                y /= p;
            }
            _ => {
                p += 1;
            }
        }
    }
    if y > 1 {
        res.push(y)
    }
    return res;
}

struct CombMod {
    facts: Vec<Mint<usize>>,
    invs: Vec<Mint<usize>>,
}

impl CombMod {
    fn new(n: usize) -> Self {
        let facts = get_factorials(n);
        let invs = get_facinvs(n, &facts);
        CombMod {
            facts: facts,
            invs: invs,
        }
    }
    fn get(&self, a: usize, b: usize) -> Mint<usize> {
        if a < b {
            Mint(0)
        } else {
            (self.facts[a as usize] * self.invs[b as usize]) * self.invs[(a - b) as usize]
        }
    }
}
pub const MOD: usize = 1000_000_007;

#[derive(Clone, Copy)]
pub struct Mint<T: Copy>(pub T);

impl Mint<usize> {
    pub fn pow(self, exp: usize) -> Self {
        let mut exp = exp;
        let mut v = self;
        let mut ret = Mint(1);
        while exp > 0 {
            if exp & 1 == 1 {
                ret *= v;
            }
            v *= v;
            exp >>= 1;
        }
        ret
    }
    pub fn inv(self) -> Self {
        self.pow(MOD - 2)
    }
}

impl Add<usize> for Mint<usize> {
    type Output = Self;
    fn add(self, rhs: usize) -> Self::Output {
        Mint((self.0 + rhs) % MOD)
    }
}

impl Add for Mint<usize> {
    type Output = Self;
    fn add(self, rhs: Self) -> Self::Output {
        self + rhs.0
    }
}

impl AddAssign<usize> for Mint<usize> {
    fn add_assign(&mut self, rhs: usize) {
        *self = *self + rhs;
    }
}

impl AddAssign for Mint<usize> {
    fn add_assign(&mut self, rhs: Self) {
        *self = *self + rhs;
    }
}

impl Sub<usize> for Mint<usize> {
    type Output = Self;
    fn sub(self, rhs: usize) -> Self::Output {
        let rhs = rhs % MOD;
        let lhs = self.0 + if self.0 < rhs { MOD } else { 0 };
        Mint(lhs - rhs)
    }
}

impl Sub for Mint<usize> {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self::Output {
        self - rhs.0
    }
}

impl SubAssign<usize> for Mint<usize> {
    fn sub_assign(&mut self, rhs: usize) {
        *self = *self - rhs
    }
}

impl SubAssign for Mint<usize> {
    fn sub_assign(&mut self, rhs: Self) {
        *self = *self - rhs
    }
}

impl Mul<usize> for Mint<usize> {
    type Output = Self;
    fn mul(self, rhs: usize) -> Self::Output {
        Mint((self.0 * rhs) % MOD)
    }
}

impl Mul for Mint<usize> {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self::Output {
        self * rhs.0
    }
}

impl MulAssign for Mint<usize> {
    fn mul_assign(&mut self, rhs: Self) {
        *self = *self * rhs;
    }
}

impl Div<usize> for Mint<usize> {
    type Output = Self;
    fn div(self, rhs: usize) -> Self::Output {
        self * Mint(rhs).pow(MOD - 2)
    }
}

impl Div for Mint<usize> {
    type Output = Self;
    fn div(self, rhs: Self) -> Self::Output {
        self / rhs.0
    }
}

impl DivAssign<usize> for Mint<usize> {
    fn div_assign(&mut self, rhs: usize) {
        *self = *self / rhs;
    }
}
impl DivAssign for Mint<usize> {
    fn div_assign(&mut self, rhs: Self) {
        *self = *self / rhs;
    }
}

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

#[derive(Clone, Copy)]
struct Ret<'a> {
    c: Mint<usize>,
    d: usize,
    comb: &'a CombMod,
}

impl<'a> Ret<'a> {
    fn new(comb: &'a CombMod) -> Self {
        Ret {
            c: Mint(1),
            d: 0,
            comb: comb,
        }
    }

    fn rooted(self) -> Self {
        Ret {
            c: self.c,
            d: self.d + 1,
            comb: self.comb,
        }
    }
}
impl<'a> Sub for Ret<'a> {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self {
        let mut c = self.c / rhs.c;
        c /= self.comb.get(self.d, rhs.d);
        Ret {
            c: c,
            d: self.d - rhs.d,
            comb: self.comb,
        }
    }
}

impl<'a> SubAssign for Ret<'a> {
    fn sub_assign(&mut self, rhs: Self) {
        *self = *self - rhs;
    }
}

impl<'a> Add for Ret<'a> {
    type Output = Self;
    fn add(self, rhs: Self) -> Self {
        let mut c = self.c * rhs.c;
        c *= self.comb.get(self.d + rhs.d, self.d);
        Ret {
            c: c,
            d: self.d + rhs.d,
            comb: self.comb,
        }
    }
}

impl<'a> AddAssign for Ret<'a> {
    fn add_assign(&mut self, rhs: Self) {
        *self = *self + rhs;
    }
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let n: usize = parse!(it);
    let mut g = vec![vec![]; n];
    let comb = CombMod::new(1000000);
    for _ in 0..(n - 1) {
        let (a, b): (usize, usize) = parse!(it, 2);
        g[a - 1].push(b - 1);
        g[b - 1].push(a - 1);
    }

    let mut dp = vec![Ret::new(&comb); n];
    let mut seen = vec![false; n];
    seen[0] = true;
    fn dfs(g: &Vec<Vec<usize>>, u: usize, seen: &mut Vec<bool>, dp: &mut Vec<Ret>) {
        for &v in &g[u] {
            if !seen[v] {
                seen[v] = true;
                dfs(g, v, seen, dp);
                let d = dp[v].rooted();
                dp[u] += d;
            }
        }
    }
    dfs(&mut g, 0, &mut seen, &mut dp);

    let mut seen = vec![false; n];
    seen[0] = true;
    fn dfs2(g: &Vec<Vec<usize>>, u: usize, seen: &mut Vec<bool>, dp: &mut Vec<Ret>) {
        for &v in &g[u] {
            if !seen[v] {
                seen[v] = true;
                let d = dp[u] - dp[v].rooted();
                dp[v] += d.rooted();
                dfs2(g, v, seen, dp);
            }
        }
    }
    dfs2(&mut g, 0, &mut seen, &mut dp);

    for i in 0..n {
        println!("{}", dp[i].c.0);
    }
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}