from collections import defaultdict

MIN = -10 ** 9
MAX = 10 ** 9 + 7


def main():
    N, K = [int(a) for a in input().split()]
    if N == 1:
        print(K)
        return
    if K == 1:
        print(0)
        return

    ab = [
        [int(a) for a in input().split()]
        for _ in range(N - 1)
    ]

    edges = defaultdict(lambda: [])
    for ai, bi in ab:
        r = edges[ai]
        r.append(bi)
        edges[ai] = r
        r = edges[bi]
        r.append(ai)
        edges[bi] = r

    childrentable = [None] * (N + 1)

    def parsetree(parent_i, current_i):
        children = []
        for nei in edges[current_i]:
            if nei == parent_i:
                continue
            parsetree(current_i, nei)
            children.append(nei)
        childrentable[current_i] = children

    parsetree(None, 1)

    if len(childrentable[1]) > K - 1:
        print(0)
        return

    def c(a, b):
        k = 1
        for i in range(b):
            if a - i <= 0:
                raise ValueError()
            k = (k * (a - i)) % MAX
        return k

    def f(index):
        target = childrentable[index]
        childcount = len(target)

        a = c(K - 2, childcount)
        for child in target:
            r = f(child) % MAX
            a = (a * r) % MAX
        return a

    try:
        result = K * c((K - 1), len(childrentable[1]))
        for child in childrentable[1]:
            r = f(child) % MAX
            result = (result * r) % MAX
    except:
        print(0)
        return
    print(result)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import defaultdict, deque
import sys
sys.setrecursionlimit(100000)

MIN = -10 ** 9
MAX = 10 ** 9 + 7


def main():
    N, K = [int(a) for a in input().split()]
    if N == 1:
        print(K)
        return
    if K == 1:
        print(0)
        return

    ab = [
        [int(a) for a in input().split()]
        for _ in range(N - 1)
    ]

    edges = defaultdict(lambda: [])
    for ai, bi in ab:
        r = edges[ai]
        r.append(bi)
        edges[ai] = r
        r = edges[bi]
        r.append(ai)
        edges[bi] = r

    childrentable = [None] * (N + 1)

    q = deque()
    q.append((None, 1))

    while len(q) != 0:
        parent_i, current_i = q.pop()

        children = []
        for nei in edges[current_i]:
            if nei == parent_i:
                continue
            q.append((current_i, nei))
            children.append(nei)
        childrentable[current_i] = children

    if len(childrentable[1]) > K - 1:
        print(0)
        return

    def c(a, b):
        k = 1
        for i in range(b):
            if a - i <= 0:
                raise ValueError()
            k = (k * (a - i)) % MAX
        return k

    def f(index):
        target = childrentable[index]
        childcount = len(target)

        a = c(K - 2, childcount)
        for child in target:
            r = f(child) % MAX
            a = (a * r) % MAX
        return a

    try:
        result = K * c((K - 1), len(childrentable[1]))
        for child in childrentable[1]:
            r = f(child) % MAX
            result = (result * r) % MAX
    except:
        print(0)
        return
    print(result)


if __name__ == '__main__':
    main()