
MOD=10**9+7

def perm(n,r)
  return 0 if r>n || n<0 || r<0
  return r.times.inject(1){|memo,i| memo*(n-i)%MOD}
end


N,K=gets.split.map(&:to_i)

edges=Array.new(N){Array.new}

(N-1).times do |i|
  a,b=gets.split.map(&:to_i)
  a-=1
  b-=1
  edges[a] << b
  edges[b] << a
end

visited=Array.new(N,false)
ans=(K*perm(K-1,edges[0].size))%MOD
visited[0]=true
stack=edges[0].dup
while !stack.empty?
  v=stack.pop
  visited[v]=true
  next if edges[v].size==1
  edges[v].each do |vv|
    stack << vv if !visited[vv]
  end
  ans=(ans*perm(K-2,edges[v].size-1))%MOD
end
p ans
