using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var nk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int n = nk[0];
			int k = nk[1];
			var to = new List<int>[n];
			for (int i = 0; i < n; i++) {
				to[i] = new List<int>();
			}

			for (int i = 0; i < n - 1; i++) {
				var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				int a = ab[0] - 1;
				int b = ab[1] - 1;
				to[a].Add(b);
				to[b].Add(a);
			}

			ModCounting.InitializeFactorial(Math.Max(n, k));
			ModInt ans = k;
			var q = new Queue<Tuple<int, int>>();
			q.Enqueue(new Tuple<int, int>(0, -1));
			while (q.Count > 0) {
				var cur = q.Dequeue();
				int toCount = to[cur.Item1].Count;
				int remColor = k - 1;
				if (cur.Item2 != -1) {
					toCount--;
					remColor--;
				}

				if (toCount == 0) {
					continue;
				}

				if (toCount > remColor) {
					Console.WriteLine(0);
					return;
				}

				ans *= ModCounting.Permutation(remColor, toCount);
				foreach (var next in to[cur.Item1]) {
					if (next != cur.Item2) {
						q.Enqueue(new Tuple<int, int>(next, cur.Item1));
					}
				}
			}

			Console.WriteLine(ans.Value);
		}
	}

	public struct ModInt
	{
		public static long Mod { get; set; } = (long)1e9 + 7;

		public static ModInt Pow(ModInt value, long k)
		{
			return Pow(value.Value, k);
		}

		public static ModInt Pow(long value, long k)
		{
			long ret = 1;
			for (k %= Mod - 1; k > 0; k >>= 1, value = value * value % Mod) {
				if ((k & 1) == 1) {
					ret = ret * value % Mod;
				}
			}
			return new ModInt(ret);
		}

		public static ModInt Inverse(ModInt value)
		{
			return Pow(value, Mod - 2);
		}

		public long Value;

		public ModInt(long value)
		{
			Value = value;
		}

		public static ModInt operator +(ModInt lhs, ModInt rhs)
		{
			lhs.Value += rhs.Value;
			if (lhs.Value >= Mod) {
				lhs.Value -= Mod;
			}
			return lhs;
		}

		public static ModInt operator -(ModInt lhs, ModInt rhs)
		{
			lhs.Value -= rhs.Value;
			if (lhs.Value < 0) {
				lhs.Value += Mod;
			}

			return lhs;
		}

		public static ModInt operator *(ModInt lhs, ModInt rhs)
		{
			return new ModInt(lhs.Value * rhs.Value % Mod);
		}
		public static ModInt operator /(ModInt lhs, ModInt rhs)
		{
			long exp = Mod - 2;
			while (exp > 0) {
				if (exp % 2 > 0) {
					lhs *= rhs;
				}

				rhs *= rhs;
				exp /= 2;
			}

			return lhs;
		}

		public static implicit operator ModInt(long n)
		{
			n %= Mod;
			if (n < 0) {
				n += Mod;
			}

			return new ModInt(n);
		}

		public override string ToString()
		{
			return Value.ToString();
		}
	}

	public static class ModCounting
	{
		private static long p_;

		private static long[] factorial_;
		private static long[] inverseFactorial_;
		private static long[] inverse_;

		public static void InitializeFactorial(long max, long p = 1000000007)
		{
			p_ = p;

			factorial_ = new long[max + 1];
			inverseFactorial_ = new long[max + 1];
			inverse_ = new long[max + 1];

			factorial_[0] = factorial_[1] = 1;
			inverseFactorial_[0] = inverseFactorial_[1] = 1;
			inverse_[1] = 1;
			for (int i = 2; i <= max; i++) {
				factorial_[i] = factorial_[i - 1] * i % p;
				inverse_[i] = p - inverse_[p % i] * (p / i) % p;
				inverseFactorial_[i] = inverseFactorial_[i - 1] * inverse_[i] % p;
			}
		}

		public static long Factorial(long n)
		{
			if (n < 0) {
				return 0;
			}

			return factorial_[n];
		}

		public static long InverseFactorial(long n)
		{
			if (n < 0) {
				return 0;
			}

			return inverseFactorial_[n];
		}

		public static long Inverse(long n)
		{
			if (n < 0) {
				return 0;
			}

			return inverse_[n];
		}

		public static long Permutation(long n, long k)
		{
			if (n < k || (n < 0 || k < 0)) {
				return 0;
			}

			return factorial_[n] * inverseFactorial_[n - k] % p_;
		}

		public static long Combination(long n, long k)
		{
			if (n < k || (n < 0 || k < 0)) {
				return 0;
			}

			return factorial_[n] * (inverseFactorial_[k] * inverseFactorial_[n - k] % p_) % p_;
		}
	}
}

Measured memory_bytes: 36216