N,K=gets.split.map(&:to_i)
connected=Array.new(N,1)
visited=Array.new(N,false)
edge=Array.new(N){Array.new}

(N-1).times do
    a,b=gets.split.map(&:to_i)
    edge[a-1].push(b-1)
    edge[b-1].push(a-1)
end

queue=Array.new
queue.push([-1,0])
res=1
until queue.empty?
    parent,e=queue.shift
    next if visited[e]
    if parent==-1 && e==0
        res*=K
        parent=0
        visited[e]=true
        edge[e].each do |n|
            queue.push([e,n])
        end
    else
        res*=K-connected[parent]
        res%=1000000007
        connected[parent]+=1
        connected[e]+=1
        visited[e]=true
        edge[e].each do |n|
            queue.push([e,n])
        end
    end 
end
puts res