Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
q=deque()
q.append(0)
e=b
while len(q):
  i=q.pop()
  f=1
  h=len(d[i])
  g[i]=1
  if i==0:
    for j in range(h):
      f=f*(b-1-j)
  else:
    if h>0:
      for j in range(h-1):
        f=f*(b-2-j)
  e=(e*f)%1000000007
  g[i]=1
  for j in range(h):
    if g[d[i][j]]==0:
      q.append(d[i][j])


print(e%1000000007)
  

Fixed submission:
from collections import deque
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
q=deque()
q.append(0)
e=b
while len(q):
  i=q.pop()
  h=len(d[i])
  g[i]=1
  if i==0:
      f=b-1
  else:
    f=b-2
  g[i]=1
  for j in range(h):
    if g[d[i][j]]==0:
      q.append(d[i][j])
      e=(e*f)%1000000007
      f-=1


print(e%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
import math
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
q=[0]
e=b
while not q==[]:
  i=q.pop()
  f=1
  h=len(d[i])
  if g[i]==0:
    if i==0:
      for j in range(h):
        f=f*(b-1-j)
    else:
      if h>0:
        for j in range(h-1):
          f=f*(b-2-j)
  e=(e*f)%1000000007
  g[i]=1
  for j in range(h):
    if g[d[i][j]]==0:
      q.append(d[i][j])


print(e%1000000007)
  

Fixed submission:
from collections import deque
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
q=deque()
q.append(0)
e=b
while len(q):
  i=q.pop()
  h=len(d[i])
  g[i]=1
  if i==0:
      f=b-1
  else:
    f=b-2
  g[i]=1
  for j in range(h):
    if g[d[i][j]]==0:
      q.append(d[i][j])
      e=(e*f)%1000000007
      f-=1


print(e%1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
import math
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
q=[0]
e=b
while not q==[]:
  i=q[-1]
  f=1
  h=len(d[i])
  if g[i]==0:
    if i==0:
      for j in range(h):
        f=f*(b-1-j)
    else:
      if h>0:
        for j in range(h-1):
          f=f*(b-2-j)
  e=(e*f)%1000000007
  k=0
  g[i]=1
  for j in range(h):
    if g[d[i][j]]==0:
      q.append(d[i][j])
      k=1
      break
  if k==0:
    q.pop()


print(e%1000000007)
  

Fixed submission:
from collections import deque
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
q=deque()
q.append(0)
e=b
while len(q):
  i=q.pop()
  h=len(d[i])
  g[i]=1
  if i==0:
      f=b-1
  else:
    f=b-2
  g[i]=1
  for j in range(h):
    if g[d[i][j]]==0:
      q.append(d[i][j])
      e=(e*f)%1000000007
      f-=1


print(e%1000000007)

Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
def s(i,d,g):
  g[i]=1
  global e
  global bb
  f=1
  h=len(d[i])
  if i==0:
    for j in range(h):
      f=f*(b-1-j)
  else:
    if h>0:
      for j in range(h-1):
        f=f*(b-2-j)
  e=(e*f)%1000000007
  for j in range(h):
    if g[d[i][j]]==0:
      s(d[i][j],d,g)
  return

e=b
s(0,d,g)
print(e%1000000007)
  

Fixed submission:
from collections import deque
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
q=deque()
q.append(0)
e=b
while len(q):
  i=q.pop()
  h=len(d[i])
  g[i]=1
  if i==0:
      f=b-1
  else:
    f=b-2
  g[i]=1
  for j in range(h):
    if g[d[i][j]]==0:
      q.append(d[i][j])
      e=(e*f)%1000000007
      f-=1


print(e%1000000007)

Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
def s(i,d,g):
  g[i]=1
  global e
  global bb
  f=1
  h=len(d[i])
  if i==0:
    for j in range(h):
      f=f*(b-1-j)
  else:
    if h>0:
      for j in range(h-1):
        f=f*(b-2-j)
  e=(e*f)%1000000007
  for j in range(h):
    if g[d[i][j]]==0:
      s(d[i][j],d,g)
  return

e=b
s(0,d,g)
print(e%1000000007)
  

Fixed submission:
from collections import deque
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
q=deque()
q.append(0)
e=b
while len(q):
  i=q.pop()
  h=len(d[i])
  g[i]=1
  if i==0:
      f=b-1
  else:
    f=b-2
  g[i]=1
  for j in range(h):
    if g[d[i][j]]==0:
      q.append(d[i][j])
      e=(e*f)%1000000007
      f-=1


print(e%1000000007)

Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
bb=math.factorial(b-2)
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
def s(i,d,g):
  g[i]=1
  global e
  global bb
  if i==0:
    f=bb*(b-1)//math.factorial(b-len(d[i])-1)
  else:
    if len(d[i])==0:
      f=1
    else:
      f=bb//math.factorial(b-len(d[i])-1)   
  e=(e*f)%1000000007
  for j in range(len(d[i])):
    if g[d[i][j]]==0:
      s(d[i][j],d,g)
  return

i=0
e=b
s(i,d,g)
print(e%1000000007)
  

Fixed submission:
from collections import deque
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
q=deque()
q.append(0)
e=b
while len(q):
  i=q.pop()
  h=len(d[i])
  g[i]=1
  if i==0:
      f=b-1
  else:
    f=b-2
  g[i]=1
  for j in range(h):
    if g[d[i][j]]==0:
      q.append(d[i][j])
      e=(e*f)%1000000007
      f-=1


print(e%1000000007)

Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
def s(i,d,g):
  g[i]=1
  global e
  if i==0:
    f=math.factorial(b-1)//math.factorial(b-len(d[i])-1)
  else:
    f=math.factorial(b-2)//math.factorial(b-len(d[i])-1)   
  e=e*f
  for j in range(len(d[i])):
    if g[d[i][j]]==0:
      s(d[i][j],d,g)
  return

i=0
e=b
s(i,d,g)
print(e%1000000007)
  

Fixed submission:
from collections import deque
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
q=deque()
q.append(0)
e=b
while len(q):
  i=q.pop()
  h=len(d[i])
  g[i]=1
  if i==0:
      f=b-1
  else:
    f=b-2
  g[i]=1
  for j in range(h):
    if g[d[i][j]]==0:
      q.append(d[i][j])
      e=(e*f)%1000000007
      f-=1


print(e%1000000007)

Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
def s(i,d,g):
  g[i]=1
  global e
  f=1
  if i==0:
    for j in range(len(d[i])):
      f=f*(b-1-j)
  else:
    for j in range(len(d[i])-1):
      f=f*(b-2-j)   
  e=e*f
  for j in range(len(d[i])):
    if g[d[i][j]]==0:
      s(d[i][j],d,g)
  return

i=0
e=b
s(i,d,g)
print(e%1000000007)
  

Fixed submission:
from collections import deque
a,b=map(int,input().split())
c=[list(map(int,input().split())) for i in range(a-1)]
d=[[]for i in range(a)]
for i in range(a-1):
  ca=c[i][0]
  cb=c[i][1]
  d[ca-1].append(cb-1)
  d[cb-1].append(ca-1)
g=[0 for i in range(a)]
q=deque()
q.append(0)
e=b
while len(q):
  i=q.pop()
  h=len(d[i])
  g[i]=1
  if i==0:
      f=b-1
  else:
    f=b-2
  g[i]=1
  for j in range(h):
    if g[d[i][j]]==0:
      q.append(d[i][j])
      e=(e*f)%1000000007
      f-=1


print(e%1000000007)