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

namespace AtCoder.Contest.E
{
	class Program
	{
		const long MOD = 1000000007;
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();

			int n = cin.nextInt();
			int k = cin.nextInt();
			var a = new int[n];
			var b = new int[n];
			var t = new Tree(n);

			for (int i = 0; i < n - 1; i++)
			{
				a[i] = cin.nextInt();
				b[i] = cin.nextInt();
				t.JoinVertex(a[i]-1, b[i]-1);
			}
			long ans = 1;

			ans = DFS(t, 0, ans, k);
			Console.WriteLine(ans);

			Console.Out.Flush();
		}

		public static long DFS(Tree t, int i, long x, long k)
		{
			long ans = x;
			t.MarkAsVisited(i);
			long temp = k;
			foreach (var item in t.GetVisitedVertex(i))
			{
				temp -= t.GetVisitedVertex(item).Count;
			}
			ans *= temp;
			ans %= MOD;
			foreach (var j in t.GetJoinedVertex(i))
			{
				if (!t.IsVisited[j])
				{
					t.VisitVertex(i, j);
					ans = DFS(t, j, ans, k);
				}
			}
			return ans;
		}

	}

	class Tree
	{
		int n;
		List<List<int>> JoinedVertex;
		List<List<int>> VisitedVertex;
		public List<bool> IsVisited;

		public Tree(int n)
		{
			this.n = n;
			JoinedVertex = new List<List<int>>(n);
			VisitedVertex = new List<List<int>>(n);
			IsVisited = new List<bool>(n);
			for (int i = 0; i < n; i++)
			{
				JoinedVertex.Add(new List<int>());
				VisitedVertex.Add(new List<int>());
				IsVisited.Add(false);
			}
		}

		public void JoinVertex(int a, int b)
		{
			JoinedVertex[a].Add(b);
			JoinedVertex[b].Add(a);
		}

		public void VisitVertex(int a, int b)
		{
			VisitedVertex[a].Add(b);
			VisitedVertex[b].Add(a);
		}

		public List<int> GetVisitedVertex(int x)
		{
			return VisitedVertex[x];
		}
		public List<int> GetJoinedVertex(int x)
		{
			return JoinedVertex[x];
		}

		public void MarkAsVisited(int x)
		{
			IsVisited[x] = true;
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return next();
			i = 0;
			return s[i++];
		}

		public int nextInt()
		{
			return int.Parse(next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextInt() + add;
			}
			return Array;
		}

		public long nextLong()
		{
			return long.Parse(next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextLong() + add;
			}
			return Array;
		}

		public double nextDouble()
		{
			return double.Parse(next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 49232