Under construction

Still being built. Things may change

Star Trek

Time limit1sMemory limit32 MB

Summary
Players alternately claim unvisited planets in a tree copied into D universes and linked by D portals; count the portal placements where the first player wins.
Level

Hard9 of 10

Topics
Game theory, Tree, Combinatorics, Dynamic programming
Solved
No attempts yet

Problem

The United Federation of Planets is an alliance of NN planets, numbered from 11 to NN. Some planets are connected by space tunnels. A starship can fly through a space tunnel in both directions very fast. There are exactly N−1N-1 space tunnels, and any planet in the Federation can reach any other planet through them.

There are DD additional parallel universes. Each one is an exact copy of our universe, with the same planets and space tunnels. They are numbered from 11 to DD, and our universe is number 00. Planet xx in universe ii is written PxiP^i_x. Travel between universes uses dimension portals. For every ii (0≤i≤D−10 \le i \le D-1), exactly one portal is placed that flies from PAiiP^i_{A_i} to PBiiP^i_{B_i}, where 1≤Ai,Bi≤N1 \le A_i, B_i \le N.

After all portals are placed, the starship Batthyány begins its maiden voyage, orbiting P10P^0_1. Captain Ágnes and Lieutenant Gábor play a game. They take turns choosing a destination planet. The destination can be in the same universe if a space tunnel leads there, or in another universe if a portal leads there. Their goal is to visit places where nobody has gone before. Once a planet PxiP^i_x has been visited, neither of them goes back there, though planet xx in another universe may still be visited. Captain Ágnes picks first, then Gábor, then Ágnes again. A player who cannot pick an unvisited planet on their turn loses.

Both players know the locations of all tunnels and portals, and both play optimally. For how many different portal placements does Captain Ágnes win? Two placements differ if, for some index ii (0≤i≤D−10 \le i \le D-1), the iith portal connects a different pair of planets in the two placements, that is, AiA_i or BiB_i differs. Give the answer modulo 109+710^9+7.

Input

The first line contains two integers NN and DD. Each of the next N−1N-1 lines contains two integers uu and vv, meaning that PuiP^i_u and PviP^i_v are connected by a space tunnel for every ii (0≤i≤D0 \le i \le D).

Output

Print one integer: the number of portal placements where Captain Ágnes wins, modulo 109+710^9+7.

Constraints

2≤N≤1052 \le N \le 10^5

1≤D≤10181 \le D \le 10^{18}

1≤u,v≤N1 \le u, v \le N

Hint

There is only 1 portal, so there are 3×3=93 \times 3 = 9 different placements. The following 4 placements are the ones where the Captain wins.

Examples1

  1. Example 1

    Input
    3 1
    1 2
    2 3
    
    Expected output
    4