Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
graph = [[] for _ in range(n+1)]
for _ in range(n-1):
    a,b=map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)
mod = 10**9 + 7
factorial = [1]*(n+1)
factorial_inv = [1]*(n+1)
for i in range(1,n+1):
    factorial[i] = factorial[i-1]*i
factorial_inv[n] = pow(factorial[n],mod-2,mod)
for i in range(n,0,-1):
    factorial_inv[i-1] = factorial_inv[i]*i%mod

for i in range(1,n+1):
    ch = [[] for _ in range(n+1)]
    pa = [0]*(n+1)
    dp = [[1,1] for _ in range(n+1)]
    checked = []
    stack = [i]
    stack2 = []
    while stack:
        a = stack.pop()
        checked.append(a)
        if a != i and len(graph[a]) == 1:
            stack2.append(a)
        else:
            for j in graph[a]:
                if j in checked:
                    continue
                else:
                    checked.append(j)
                    stack.append(j)
                    pa[j] = a
                    ch[a].append(j)
    checked = []
    while stack2:
        a = stack2.pop()
        if a == i:
            print(dp[i][0])
            break
        else:
            p = pa[a]
            dp[p][0] *= dp[a][0]*factorial_inv[dp[a][1]]
            dp[p][0] %= mod
            dp[p][1] += dp[a][1]
            ch[p].remove(a)
            if len(ch[p]) == 0:
                dp[p][0] *= factorial[dp[p][1]-1]
                dp[p][0] %= mod
                stack2.append(p)
            checked.append(a)

Fixed submission:
n = int(input())
graph = [[] for _ in range(n+1)]
for _ in range(n-1):
    a,b=map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)
mod = 10**9 + 7
factorial = [1]*(n+1)
factorial_inv = [1]*(n+1)
for i in range(1,n+1):
    factorial[i] = factorial[i-1]*i%mod
factorial_inv[n] = pow(factorial[n],mod-2,mod)
for i in range(n,0,-1):
    factorial_inv[i-1] = factorial_inv[i]*i%mod

pa = [0]*(n+1)
dp = [1]*(n+1)
size = [1]*(n+1)
checked = []
stack = [i]
while stack:
    a = stack.pop()
    checked.append(a)
    for j in graph[a]:
        if pa[a] == j:   
            continue
        else:
            stack.append(j)
            pa[j] = a

for i in checked[::-1]:
    p = pa[i]
    s = size[i]
    dp[i] *= factorial[s-1]
    dp[i] %= mod
    dp[p] *= dp[i]*factorial_inv[s]
    dp[p] %= mod
    size[p] += s

size_ = [n-i+1 for i in size]
dp_ = [1]*(n+1)
for i in checked[1:]:
    p = pa[i]
    dp_[i] *= dp[p]
    dp_[i] *= factorial_inv[size[p]-1]
    dp_[i] *= pow(dp[i],mod-2,mod)
    dp_[i] *= factorial[size[i]]
    dp_[i] *= dp_[p]
    dp_[i] *= factorial_inv[size_[p]-1]
    dp_[i] *= factorial[size_[i]-2]
    dp_[i] %= mod
    
for i in range(1,n+1):
    ans = factorial[n-1]*dp[i]*dp_[i]*factorial_inv[size[i]-1]*factorial_inv[size_[i]-1]
    ans %= mod
    print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
graph = [[] for _ in range(n)]
factorial = [1]*(n+1)
for i in range(1,n+1):
    factorial[i] = factorial[i-1]*i
mod = 10**9 + 7
for _ in range(n-1):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

for i in range(n):
    ch = [[] for _ in range(n)]
    pa = [[] for _ in range(n)]
    dp = [[1,1] for _ in range(n)]
    checked = []
    stack = [i]
    stack2 = []
    while stack:
        a = stack.pop()
        checked.append(a)
        if a != i and len(graph[a]) == 1:
            stack2.append(a)
        else:
            for j in graph[a]:
                if j in checked:
                    continue
                else:
                    checked.append(j)
                    stack.append(j)
                    pa[j].append(a)
                    ch[a].append(j)
    checked = []
    while stack2:
        a = stack2.pop()
        if a == i:
            print(dp[i][0])
            break
        else:
            p = pa[a][0]
            dp[p][0] *= dp[a][0]*pow(factorial[dp[a][1]],mod-2,mod)
            dp[p][0] %= mod
            dp[p][1] += dp[a][1]
            ch[p].remove(a)
            if len(ch[pa[a][0]]) == 0:
                dp[p][0] *= factorial[dp[p][1]-1]
                dp[p][0] %= mod
                stack2.append(p)
            checked.append(a)

Fixed submission:
n = int(input())
graph = [[] for _ in range(n+1)]
for _ in range(n-1):
    a,b=map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)
mod = 10**9 + 7
factorial = [1]*(n+1)
factorial_inv = [1]*(n+1)
for i in range(1,n+1):
    factorial[i] = factorial[i-1]*i%mod
factorial_inv[n] = pow(factorial[n],mod-2,mod)
for i in range(n,0,-1):
    factorial_inv[i-1] = factorial_inv[i]*i%mod

pa = [0]*(n+1)
dp = [1]*(n+1)
size = [1]*(n+1)
checked = []
stack = [i]
while stack:
    a = stack.pop()
    checked.append(a)
    for j in graph[a]:
        if pa[a] == j:   
            continue
        else:
            stack.append(j)
            pa[j] = a

for i in checked[::-1]:
    p = pa[i]
    s = size[i]
    dp[i] *= factorial[s-1]
    dp[i] %= mod
    dp[p] *= dp[i]*factorial_inv[s]
    dp[p] %= mod
    size[p] += s

size_ = [n-i+1 for i in size]
dp_ = [1]*(n+1)
for i in checked[1:]:
    p = pa[i]
    dp_[i] *= dp[p]
    dp_[i] *= factorial_inv[size[p]-1]
    dp_[i] *= pow(dp[i],mod-2,mod)
    dp_[i] *= factorial[size[i]]
    dp_[i] *= dp_[p]
    dp_[i] *= factorial_inv[size_[p]-1]
    dp_[i] *= factorial[size_[i]-2]
    dp_[i] %= mod
    
for i in range(1,n+1):
    ans = factorial[n-1]*dp[i]*dp_[i]*factorial_inv[size[i]-1]*factorial_inv[size_[i]-1]
    ans %= mod
    print(ans)