using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Runtime.CompilerServices;

public class Contest
{
	static void Swap<T>(ref T lhs, ref T rhs) { T temp; temp = lhs; lhs = rhs; rhs = temp; }
	public const long MOD1 = 1000000007L; // 10^9+7

	public static void Main() {
		int  n, k;
		VT<int,int>[] abl;
		MyIO.ReadMulti(out n, out k);
 
		if(n==1) {
			MyIO.WriteMulti(k);
			return;
		}
 
		MyIO.ReadLines(n-1, out abl);
 
		List<int>[] tr = new List<int>[n];
		foreach (var e in abl)
		{
			if(tr[e.Item1-1]== null) tr[e.Item1-1] = new List<int>();
			if(tr[e.Item2-1]== null) tr[e.Item2-1] = new List<int>();
			tr[e.Item1-1].Add(e.Item2-1);
			tr[e.Item2-1].Add(e.Item1-1);
		}
 

		ModCombination mc = new ModCombination(k,MOD1);
		long sum = (k*mc.P(k-1,tr[0].Count).Value)%MOD1;

		Func<int,int,bool> dfs1 = null;
		dfs1 = (p,i)=>{
			if(k<tr[i].Count) sum=0;
			if(p!=-1)sum = (sum*mc.P(k-2,tr[i].Count-1).Value)%MOD1;
			foreach(var e in tr[i]) if(e!=p) dfs1(i,e);
			return true;
		};

		dfs1(-1,0);
 
 
		MyIO.WriteMulti(sum);
 
	}








}


public class ModCombination {
	private ModInt[] _fact, _rfact, _inv;
	private ModInt[] _mm;

	public ModCombination(int sz) : this(sz, long.MaxValue) {}
	public ModCombination(int sz, long modulo){
		_fact = new ModInt[sz+1];
		_rfact = new ModInt[sz+1];
		_inv = new ModInt[sz+1];

		_mm = new ModInt[]{new ModInt(0,modulo), new ModInt(1,modulo)};
		
		_fact[0] = _rfact[sz] = _inv[0] = _mm[1];
		for(int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i;
		_rfact[sz] /= _fact[sz];
		for(int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
		for(int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1];
	}

	public ModInt P(int n, int r) {
		if(r < 0 || n < r) return _mm[0];
		return _fact[n] * _rfact[n - r];
	}

	public ModInt C(int n, int r) {
		if(r < 0 || n < r) return _mm[0];
		return _fact[n] * _rfact[r] * _rfact[n - r];
	}

	public ModInt H(int n, int r) {
		if(n < 0 || r < 0) return _mm[0];
		return r == 0 ? _mm[1] : C(n + r - 1, r);
	}
	
	public ModInt B(int n, int k) {
		if(n == 0) return _mm[1];
		k = k<n ? k : n;
		ModInt ret = _mm[0];
		long mo = _mm[0].Modulo;
		ModInt[] pref = new ModInt[k + 1];
		pref[0] = _mm[1];
		for(int i = 1; i <= k; i++) {
			if((i & 1)==1) pref[i] = pref[i - 1] - _rfact[i];
			else pref[i] = pref[i - 1] + _rfact[i];
		}
		for(int i = 1; i <= k; i++) ret += (new ModInt(i, mo)).Pow(n) * _rfact[i] * pref[k - i];

		return ret;
	}
	
	public ModInt S(int n, int k) {
		ModInt ret = _mm[0];
		long mo = _mm[0].Modulo;
		for(int i = 0; i <= k; i++) {
			var add = (new ModInt(i, mo)).Pow(n) * this.C(k, i);
			if(((k - i) & 1)==1) ret -= add;
			else ret += add;
		}
		return ret * _rfact[k];
	}

	public static ModInt[][] PartitionTable(int n, int k, long modulo=long.MaxValue) {
		ModInt[][] dp = new ModInt[n + 1][];
		for(int i=0;i<=n;i++) dp[i] = new ModInt[k + 1];
		dp[0][0] = new ModInt(1, modulo);
		for(int i = 0; i <= n; i++) {
			for(int j = 1; j <= k; j++) {
				if(i - j >= 0) dp[i][j] = dp[i][j - 1] + dp[i - j][j];
				else dp[i][j] = dp[i][j - 1];
			}
		}
		return dp;
	}


}

public struct ModInt {
	public long Value;
	public long Modulo;

	public ModInt(long value) : this(value, long.MaxValue) {}
	public ModInt(long value, long modulo) {
		this.Modulo = modulo;
		this.Value = value >= 0 ? value % modulo : (modulo - (-value) % modulo) % modulo;
	}

    public static implicit operator ModInt(long v) { return new ModInt(v, 1000000007L); }
	public static ModInt operator-(ModInt a) { return new ModInt(-1*a.Value, a.Modulo); }
	public static ModInt operator+(ModInt a, ModInt b) { return new ModInt(a.Value + b.Value, a.Modulo); }
	public static ModInt operator-(ModInt a, ModInt b) { return new ModInt(a.Value - b.Value, a.Modulo); }
	public static ModInt operator*(ModInt a, ModInt b) { return new ModInt(a.Value * b.Value, a.Modulo); }
	public static ModInt operator/(ModInt a, ModInt b) { return a * b.Inverse(); }
	public static bool operator==(ModInt a, ModInt b) { return a.Equals(b); }
	public static bool operator!=(ModInt a, ModInt b) { return !a.Equals(b); }

	public ModInt Inverse() {
		long a = this.Value, b = this.Modulo, u = 1, v = 0, t, s;
		while(b > 0) {
			t = a / b;
			s = a - t * b; a = b; b = s;
			s = u - t * v; u = v; v = s;
		}
		return new ModInt(u, this.Modulo);
	}

	public ModInt Pow(int n) {
		ModInt ret = new ModInt(1, this.Modulo);
		ModInt mul = new ModInt(this.Value, this.Modulo);
		while(n > 0) {
			if((n & 1)==1) ret *= mul;
			mul *= mul;
			n >>= 1;
		}
		return ret;
	}

    public override bool Equals(object obj) {
        if (!(obj is ModInt)) throw new ArgumentException("Object is not a ModInt");
        return Equals((ModInt)obj);   
    }
    public bool Equals(ModInt p) => (this.Value == p.Value);
    public override int GetHashCode() => (int)(this.Value ^ this.Modulo);
	public override string ToString() => this.Value.ToString();

}






#region MyIO

public struct VT<T, U>
{
	public T Item1; public U Item2;
    public VT(T a, U b) { Item1 = a; Item2 = b; }
}
public struct VT<T, U, V>
{
	public T Item1; public U Item2; public V Item3;
    public VT(T a, U b, V c) { Item1 = a; Item2 = b; Item3 = c; }
}
public struct VT<T, U, V, W>
{
	public T Item1; public U Item2; public V Item3; public W Item4;
    public VT(T a, U b, V c, W d) { Item1 = a; Item2 = b; Item3 = c; Item4 = d; }
}

public class Printer : System.IO.StreamWriter
{
	public override IFormatProvider FormatProvider { get { return System.Globalization.CultureInfo.InvariantCulture; } }
	public Printer(System.IO.Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
	public Printer(System.IO.Stream stream, Encoding encoding) : base(stream, encoding) { }
}
public static class MyIO
{
	private static char[] splitter = new char[] {' '};
	private static bool eq<T, U>() => typeof(T).Equals(typeof(U));
	private static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
	private static T cv<T>(string s) =>
		eq<T, int>()    ? ct<T, int>(int.Parse(s))
	  : eq<T, long>()   ? ct<T, long>(long.Parse(s))
	  : eq<T, double>() ? ct<T, double>(double.Parse(s, System.Globalization.CultureInfo.InvariantCulture))
	  : eq<T, char>()   ? ct<T, char>(s[0])
						: ct<T, string>(s);
			
	public static string[] ReadMulti<T>(out T a) {
		var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries); 
		a = cv<T>(ar[0]);
		return ar;
	}
	public static string[] ReadMulti<T, U>(out T a, out U b) {
		var ar = ReadMulti<T>(out a); 
        b = cv<U>(ar[1]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V>(out T a, out U b, out V c) {
		var ar = ReadMulti<T, U>(out a, out b); 
        c = cv<V>(ar[2]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V, W>(out T a, out U b, out V c, out W d) {
		var ar = ReadMulti<T, U, V>(out a, out b, out c); 
        d = cv<W>(ar[3]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) {
		var ar = ReadMulti<T, U, V, W>(out a, out b, out c, out d); 
        e = cv<X>(ar[4]);
		return ar;
	}
	public static string[] ReadMulti<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) {
		var ar = ReadMulti<T, U, V, W, X>(out a, out b, out c, out d, out e); 
        f = cv<Y>(ar[5]);
		return ar;
	}
	public static string[] ReadArray<T>(out T[] a) {		
		var ar = Console.ReadLine().Split(splitter, StringSplitOptions.RemoveEmptyEntries);
		a = ar.Select(cv<T>).ToArray();
		return ar;
	}		
	public static string[][] ReadLines<T>(int n, out T[] a) {
		a = new T[n];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) arr[i] = ReadMulti(out a[i]);
		return arr;
	}
	public static string[][] ReadLines<T, U>(int n, out VT<T, U>[] a) {
		a = new VT<T, U>[n];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) {
			T o; U p;
			arr[i] = ReadMulti(out o, out p);
			a[i] = new VT<T, U>(o, p);
		}
		return arr;
	}
	public static string[][] ReadLines<T, U, V>(int n, out VT<T, U, V>[] a) {
		a = new VT<T, U, V>[n];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) {
			T o; U p; V q;
			arr[i] = ReadMulti(out o, out p, out q);
			a[i] = new VT<T, U, V>(o, p, q);
		}
		return arr;
	}
	public static string[][] ReadLines<T, U, V, W>(int n, out VT<T, U, V, W>[] a) {
		a = new VT<T, U, V, W>[n];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) {
			T o; U p; V q; W r;
			arr[i] = ReadMulti(out o, out p, out q, out r);
			a[i] = new VT<T, U, V, W>(o, p, q, r);
		}
		return arr;
	}
	public static string[][] ReadMatrix<T>(int n, out T[][] a) {
		a = new T[n][];
		string[][] arr = new string[n][];
		for(int i=0; i<n; i++) arr[i] = ReadArray(out a[i]);
		return arr;
	}

	private static void wwp(Action act){
		var sw = new Printer(Console.OpenStandardOutput()){AutoFlush = false};
		Console.SetOut(sw);
		act();
		Console.Out.Flush();
		sw.AutoFlush = true;
		Console.SetOut(sw);
	}
	private static string wfm(Type t) =>t.Equals(typeof(double)) ? "{0:F10}" : "{0}";
	public static void WriteMulti(params object[] a) {
		wwp(()=>{
			for(int i=0;i<a.Length;i++) {
				string fs = wfm(a[i].GetType()) + ((i<a.Length-1) ? " " : Environment.NewLine);
				Console.Write(fs, a[i]);
			}
		});
	}
	public static void WriteArray<T>(T[] a) {
		wwp(()=>{
			string fs = wfm(typeof(T));
			string fs1 = fs + " ";
			string fs2 = fs + Environment.NewLine;
			for(int i=0;i<a.Length;i++) Console.Write( ((i<a.Length-1) ? fs1 : fs2), a[i]);
		});
	}
	public static void WriteLines<T>(T[] a) {
		wwp(()=>{
			string fs = wfm(typeof(T)) + Environment.NewLine;
			foreach(T x in a) Console.Write(fs, x);
		});
	}



}

#endregion



Measured memory_bytes: 45460