n,c=map(int,input().split()) edge=[] for _ in range(n-1): a,b=map(int,input().split()) a-=1 b-=1 edge.append((a,b)) ans=0 for i in range(c**n): color=[] for j in range(n): color.append(i%c) i//=c flag=True for a,b in edge: if abs(color[a]-color[b])!=3:flag=False ans+=flag print(ans)