n,k=gets.split.map(&:to_i)
$kiarray=[]
n.times{
    $kiarray<<[]
}
$parentarray=Array.new(n,0)
$parentarray[0]=-1
$childCount=Array.new(n,0)

(n-1).times{
    a,b=gets.split.map(&:to_i)
    $kiarray[a-1].push(b)
    $kiarray[b-1].push(a)
}

def searchChild(node)
    
    $childArray=$kiarray[node-1]
    $childArray.map{|i|
        if $parentarray[i-1]==0
            $parentarray[i-1]=node
            searchChild(i)
        end
    }
    
end



searchChild(1)


j=1
(n-1).times{
    parent=$parentarray[j]
    $childCount[parent-1]+=1
    j+=1
}

answer=k

index=k-1
$childCount[0].times{
    answer*=index
    index-=1
}

s=1
(n-1).times{
    
        index=k-2
       $childCount[s].times{
        answer*=index
        index-1
        }
   
   s+=1 
}

p answer%1000000007