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)

fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut solver = Solver::new(n);
    for _ in 0..n - 1 {
        solver.add_edge(scan(tokens), scan(tokens));
    }
    solver.solve();
}

const MODULO: usize = 1_000_000_007;

struct Solver {
    n: usize,
    edges: Vec<Vec<usize>>,
    parent: Vec<usize>,
    c: Vec<usize>,
    x: Vec<usize>,
    y: Vec<usize>,
    f: Vec<usize>,
}

impl Solver {
    fn new(n: usize) -> Solver {
        let mut f = vec![0; n + 1];
        f[0] = 1;
        for i in 1..f.len() {
            f[i] = i * f[i - 1] % MODULO;
        }
        Solver {
            n: n,
            edges: vec![Vec::new(); n + 1],
            parent: vec![0; n + 1],
            c: vec![0; n + 1],
            x: vec![0; n + 1],
            y: vec![0; n + 1],
            f: f,
        }
    }
    fn add_edge(&mut self, a: usize, b: usize) {
        self.edges[a].push(b);
        self.edges[b].push(a);
    }
    fn solve(&mut self) {
        self.dfs(1);
        self.dfs2(1);
        for i in 1..self.n + 1 {
            if i == 1 {
                println!("{}", self.x[i]);
            } else {
                let mut z = self.y[i];
                z = z * inverse(self.f[self.n - self.c[i]]) % MODULO;
                z = z * self.x[i] % MODULO;
                z = z * inverse(self.f[self.c[i] - 1]) % MODULO;
                z = z * self.f[self.n - 1] % MODULO;
                println!("{}", z);
            }
        }
    }
    fn dfs(&mut self, i: usize) {
        let mut c = 1;
        let mut x = 1;
        for idx in 0..self.edges[i].len() {
            let j = self.edges[i][idx];
            if j != self.parent[i] {
                self.parent[j] = i;
                self.dfs(j);
                c = c + self.c[j];
                x = x * self.x[j] % MODULO;
                x = x * inverse(self.f[self.c[j]]) % MODULO;
            }
        }
        x = x * self.f[c - 1] % MODULO;
        self.c[i] = c;
        self.x[i] = x;
    }
    fn dfs2(&mut self, i: usize) {
        if i == 1 {
            self.y[i] = 1;
        } else {
            let p = self.parent[i];
            let mut y = self.y[p] * inverse(self.f[self.n - self.c[p]]) % MODULO;
            for idx in 0..self.edges[p].len() {
                let j = self.edges[p][idx];
                if j != self.parent[p] && j != i {
                    y = y * self.x[j] % MODULO;
                    y = y * inverse(self.f[self.c[j]]) % MODULO;
                }
            }
            y = y * self.f[self.n - self.c[i] - 1] % MODULO;
            self.y[i] = y;
        }
        for idx in 0..self.edges[i].len() {
            let j = self.edges[i][idx];
            if j != self.parent[i] {
                self.dfs2(j);
            }
        }
    }
}

fn power(mut b: usize, mut e: usize) -> usize {
    let mut a = 1;
    while e != 0 {
        if e & 1 != 0 {
            a = a * b % MODULO;
        }
        b = b * b % MODULO;
        e >>= 1;
    }
    a
}

fn inverse(x: usize) -> usize {
    power(x, MODULO - 2)
}