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 Kotlin (1.0.0) (judge verdict: Accepted)

import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

val MOD = 1000000007L

fun main(omkar: Array<String>) {
    val jin = BufferedReader(InputStreamReader(System.`in`))
    val n = jin.readLine().toInt()
    val adj = Array(n + 1) { mutableSetOf<Int>() }
    for (j in 2..n) {
        val tokenizer = StringTokenizer(jin.readLine())
        val a = tokenizer.nextToken().toInt()
        val b = tokenizer.nextToken().toInt()
        adj[a].add(b)
        adj[b].add(a)
    }
    val inv = LongArray(n + 1) { it.toLong() pow -1 }
    val subTree = IntArray(n + 1) { 1 }
    val dp = LongArray(n + 1) { 1L }
    fun recur1(a: Int) {
        for (b in adj[a]) {
            adj[b].remove(a)
            recur1(b)
            subTree[a] += subTree[b]
            dp[a] *= (dp[b] * inv[subTree[b]]) % MOD
            dp[a] %= MOD
        }
    }
    recur1(1)
    dp[1] = dp[1]
    for (j in 1 until n) {
        dp[1] *= j.toLong()
        dp[1] %= MOD
    }
    fun recur2(a: Int, parentDP: Long) {
        if (a != 1) {
            dp[a] = parentDP
            dp[a] *= subTree[a].toLong()
            dp[a] %= MOD
            dp[a] *= inv[n - subTree[a]]
            dp[a] %= MOD
        }
        for (b in adj[a]) {
            recur2(b, dp[a])
        }
    }
    recur2(1, 0)
    println(dp.joinToString("\n").substring(2))
}

val MOD_TOTIENT = (MOD - 1).toInt()

infix fun Long.pow(power: Int): Long {
    var e = power
    e %= MOD_TOTIENT
    if (e < 0) {
        e += MOD_TOTIENT
    }
    if (e == 0 && this == 0L) {
        return this
    }
    var b = this % MOD
    var res = 1L
    while (e > 0) {
        if (e and 1 != 0) {
            res *= b
            res %= MOD
        }
        b *= b
        b %= MOD
        e = e shr 1
    }
    return res
}