Buggy python submission (verdict: Runtime Error):
n, K = map(int, input().split())

mo = 1000000007
ret = 1
E = [[] for _ in range(n)]
def dfs(cur, pre, cand):
    global ret
    ret = ret * cand
    k = 0
    if pre != -1:
        k = 1
    cand = K - 1 - k
    for e in E[cur]:
        if e != pre:
            dfs(e, cur, cand)
            cand -= 1

for _ in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

dfs(0, -1, K)
print(ret % mo)


Fixed submission:
import sys

sys.setrecursionlimit(10**9)

n, K = map(int, input().split())

mo = 1000000007
ret = 1
E = [[] for _ in range(n)]

def dfs(cur, pre, cand):
    global ret
    ret = (ret % mo * (cand % mo)) % mo
    k = 0
    if pre != -1:
        k = 1
    cand = K - 1 - k
    for e in E[cur]:
        if e != pre:
            dfs(e, cur, cand)
            cand -= 1

for _ in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

dfs(0, -1, K)
print(ret % mo)

Buggy python submission (verdict: Runtime Error):
n, K = map(int, input().split())

mo = 1000000007
ret = 1
E = [[] for _ in range(n)]
def dfs(cur, pre, cand):
    global ret
    ret = ret * cand
    k = 0
    if pre != -1:
        k = 1
    cand = K - 1 - k
    for e in E[cur]:
        if e != pre:
            dfs(e, cur, cand)
            cand -= 1

for _ in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

dfs(0, -1, K)
print(ret % mo)


Fixed submission:
import sys

sys.setrecursionlimit(10**9)

n, K = map(int, input().split())

mo = 1000000007
ret = 1
E = [[] for _ in range(n)]

def dfs(cur, pre, cand):
    global ret
    ret = (ret % mo * (cand % mo)) % mo
    k = 0
    if pre != -1:
        k = 1
    cand = K - 1 - k
    for e in E[cur]:
        if e != pre:
            dfs(e, cur, cand)
            cand -= 1

for _ in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

dfs(0, -1, K)
print(ret % mo)

Buggy python submission (verdict: Runtime Error):
n, K = map(int, input().split())

mo = 1000000007
ret = 1
E = [[] for _ in range(n)]
def dfs(cur, pre, cand):
    global ret
    ret = ret * cand
    cand = K - 1 - (pre != -1)
    for e in E[cur]:
        if e != pre:
            dfs(e, cur, cand)
            cand -= 1

for _ in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

dfs(0, -1, K)
print(ret % mo)


Fixed submission:
import sys

sys.setrecursionlimit(10**9)

n, K = map(int, input().split())

mo = 1000000007
ret = 1
E = [[] for _ in range(n)]

def dfs(cur, pre, cand):
    global ret
    ret = (ret % mo * (cand % mo)) % mo
    k = 0
    if pre != -1:
        k = 1
    cand = K - 1 - k
    for e in E[cur]:
        if e != pre:
            dfs(e, cur, cand)
            cand -= 1

for _ in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

dfs(0, -1, K)
print(ret % mo)

Buggy python submission (verdict: Runtime Error):
n, K = map(int, input().split())

mo = 10 ** 10 + 7
ret = 1
E = [[] for _ in range(n)]
def dfs(cur, pre, cand):
    global ret
    ret = ret * cand % mo
    cand = K - 1 - (pre != -1)
    for e in E[cur]:
        if e != pre:
            dfs(e, cur, cand)
            cand -= 1

for _ in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

dfs(0, -1, K)
print(ret)


Fixed submission:
import sys

sys.setrecursionlimit(10**9)

n, K = map(int, input().split())

mo = 1000000007
ret = 1
E = [[] for _ in range(n)]

def dfs(cur, pre, cand):
    global ret
    ret = (ret % mo * (cand % mo)) % mo
    k = 0
    if pre != -1:
        k = 1
    cand = K - 1 - k
    for e in E[cur]:
        if e != pre:
            dfs(e, cur, cand)
            cand -= 1

for _ in range(n-1):
    a, b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)

dfs(0, -1, K)
print(ret % mo)