import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
void solve(){
	int n = read.to!int;
	long k = read.to!long;
	
	Node.k = k;
	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i);
 
	foreach(i; 0 .. n - 1){
	 int x = read.to!int - 1;
	 int y = read.to!int - 1;
	 nodes[x].nodes ~= nodes[y];
	 nodes[y].nodes ~= nodes[x];
 }
	
	nodes[0].treefy(null);
	
	Finite ans = Finite(k);
	foreach(i, kid; nodes[0].kids){
		ans *= k - 1 - i;
		ans *= kid.value;
	}
	
	ans.writeln;
}
/*
木DP。
「親が1色取り、私の色をきめられたとき、私より下を塗り分ける場合の数はxです。」を返す。

それは
私の子たちを何でぬるか（親の色、私の色以外ですべて異なる色）
私の子よりも下を何でぬるか（DPで来る）
の積。

ルートの直接の子にこれを訊けば答えが出る。

*/
class Node{
	int id;
	static long k;
	Node[] nodes;
	Node[] kids;
	Node parent;
	bool isVisited;
	this(int id){
		this.id = id;
	}
	void treefy(Node parent){
		this.parent = parent;
		foreach(nd; nodes) if(!parent || nd.id != parent.id) this.kids ~= nd, nd.treefy(this);
	}
	Finite value(){
		Finite res = Finite(1);
		foreach(i, kid; kids){
			res *= k - 2 - i;
			res *= kid.value;
		}
		return res;
	}
	override string toString(){
		return "id:" ~ id.to!string ~ " value:" ~ value.to!string ~ " kids:" ~ kids.map!(x => x.id).to!string;
	}
}


struct Finite{ ulong value; static ulong mod = 1_000_000_007;
	private static ulong[] _inv = [0, 1], _frac = [1, 1], _invfrac = [1, 1];
	this(ulong v){ value = v % mod; }
	bool opCast(T: bool)(){ return value != 0; }
	Finite opUnary(string s){ ulong v;
		if(s == "+") v = value;
		else if(s == "-") v = mod - value;
		else if(s == "++") v = value + 1;
		else if(s == "--") v = value + mod - 1;
		else assert(0, "Operator unary " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opBinary(string s)(Finite b){
		return opBinary!s(b.value);
	}
	Finite opBinary(string s)(ulong u){ ulong v;
		if(s == "+") v = value + u;
		else if(s == "-") v = value + mod - u;
		else if(s == "*") v = value * u;
		else if(s == "/") v = value * inv(u);
		else assert(0, "Operator " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opBinaryRight(string s)(ulong u){ ulong v;
		if(s == "+") v = u + value;
		else if(s == "-") v = u + mod - value;
		else if(s == "*") v = u * value;
		else if(s == "/") v = u * invvalue;
		else assert(0, "Operator " ~ s ~ " not implemented");
		return Finite(v);
	}
	Finite opAssign(ulong v){ value = v; return this; }
	Finite opOpAssign(string s)(Finite b){
		return opOpAssign!s(b.value);
	}
	Finite opOpAssign(string s)(ulong v){
		if(s == "+") value = (value + v) % mod;
		else if(s == "-") value = (value + mod - v) % mod;
		else if(s == "*") value = (value * v) % mod;
		else if(s == "/") value = (value * inv(v)) % mod;
		else assert(0, "Operator " ~ s ~ "= not implemented");
		return this;
	}
	bool opEquals(Finite b){
		return(value == b.value);
	}
	string toString(){ return value.to!string; }
	ulong inv(ulong v){
		assert(v > 0);
		assert(v < mod);
		while(v >= _inv.length){
			_inv ~= _inv[mod % $] * (mod - mod / _inv.length) % mod;
		}
		return _inv[v];
	}
	ulong invvalue(){
		return inv(value);
	}
	static Finite opCall(ulong v){
		return Finite(v);
	}
}
