mod = 1000000007
str = gets.split
N,K = str[0].to_i, str[1].to_i
r = Array.new(N+1){Array.new(0)}

a = 0
b = 0
for x in 1...N do
    str = gets.split
    a,b = str[0].to_i, str[1].to_i
    r[a].push(b)
    r[b].push(a)
end

s = Array.new(0)
s.push(1)
answer = K
now = s.pop
if r[now].size > 0
    a = r[now].size
    for x in 1..a do
        answer = answer * (K-x) % mod
    end
    while r[now].size > 0
        b = r[now].pop
        if r[b].size != 0
            s.push(b)
        end 
    end
end
while s.size > 0
    now = s.pop
    if r[now].size > 0
        a = r[now].size
        for x in 1...a do
            answer = answer * (K-1-x) % mod
        end
        while r[now].size > 0
            b = r[now].pop
            if r[b].size != 0
                s.push(b)
            end 
        end
    end
end

puts answer