Pagini recente » Cod sursa (job #2779093) | Cod sursa (job #2346823) | Cod sursa (job #2123055) | Cod sursa (job #3164781) | Cod sursa (job #466142)
Cod sursa(job #466142)
type vec=record
a:array of longint;
end;
var v:array[1..100000]of vec;
l,u,q:array[1..100000]of 1..100000;
n,k,a,b,x,y,i,j,o,d,ll:longint;
h:qword;
ok:boolean;
function p(c,l:longint):qword;
var i:longint;
begin
p:=1;
for i:=1 to l do
begin
p:=(p*c) mod 1000000007;
dec(c);
end;
end;
begin
assign(input,'colorare3.in');
assign(output,'colorare3.out');
reset(input);
rewrite(output);
readln(n,k);
for i:=1 to n-1 do
begin
read(x,y);
inc(l[x]);
setlength(v[x].a,l[x]+1);
v[x].a[l[x]]:=y;
inc(l[y]);
setlength(v[y].a,l[y]+1);
v[y].a[l[y]]:=x;
end;
close(input);
h:=1;
i:=1;
o:=1;
q[o]:=1;
while i<=o do
begin
ll:=0;
ok:=false;
if i=2 then dec(k);
for j:=1 to l[q[i]] do
if u[q[i]]<>v[q[i]].a[j] then
begin
u[v[q[i]].a[j]]:=q[i];
inc(ll);
inc(o);
q[o]:=v[q[i]].a[j];
ok:=true;
end;
if ok then
h:=h*(p(k,ll) mod 1000000007);
i:=i+1;
end;
write(h);
close(output);
end.