#P6803. [CEOI 2020] 星际迷航

    ID: 5847 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2020CEOI矩阵加速,矩阵优化树形 dp

[CEOI 2020] 星际迷航

Description

The Interstellar Federation consists of NN planets, numbered 1N1 \sim N. Some planets are connected by interstellar passages. Through these passages, a spaceship can travel back and forth between planets in a short time. There are exactly N1N-1 interstellar passages in the whole federation, and using these passages, it is possible to travel between any two planets.

Besides our universe, there are DD parallel universes. These parallel universes are exact copies of our universe: their planets and interstellar passages are exactly the same as ours. We number these parallel universes as 1D1 \sim D (our universe is numbered 00), and denote the xx-th planet in the ii-th universe by PxiP_{x}^i. Using stargates, we can travel among these parallel universes. For all i[0,D)i \in [0,D), we will choose one AiA_i and one BiB_i (with 1Ai,BiN1 \leq A_i,B_i \leq N), and build a one-way (only from PAiiP_{A_i}^i to PBii+1P_{B_i}^{i+1}) stargate between PAiiP_{A_i}^i and PBii+1P_{B_i}^{i+1}.

After all stargates are ready, the Federation starship Batthyány will start its maiden voyage. It is currently orbiting planet P10P_1^0. Captain Ágnes plans to play the following game with Lieutenant Gábor: the two players alternately choose the next destination of the starship, and the destination must be directly reachable via an interstellar passage or a stargate. They want each visited planet to be one that has not been visited before. That is, if the starship arrives at PxiP_{x}^i, then they will never pass through that planet again (but they may still arrive at the corresponding planet xx in other parallel universes). Captain Ágnes moves first, Lieutenant Gábor moves second. If a player, on their turn, cannot choose a legal destination, then that player loses the game.

Both the captain and the lieutenant are perfectly smart. They know the full layout of all interstellar passages and stargates, and they always play optimally. You need to find how many stargate layouts make Captain Ágnes (the first player) guaranteed to win. Two stargate layouts are different if and only if there exists an integer ii such that AiA_i or BiB_i is different.

Input Format

The first line contains two integers N,DN,D, representing the number of planets in the federation and the number of parallel universes.

The next N1N-1 lines each contain two integers u,vu,v, meaning that for all i[0,D]i \in [0,D], there is an interstellar passage connecting PuiP_u^i and PviP_v^i.

Output Format

Output the number of stargate layouts that make the captain guaranteed to win, modulo 109+710^9+7.

3 1
1 2
2 3
4

Hint

Sample Explanation

There are 3×3=93 \times 3=9 essentially different stargate layouts in total. Four winning cases for the captain are listed below.

Subtasks

All testdata satisfy: 1N1051 \leq N \leq 10^5, 1D10181 \leq D \leq 10^{18}, 1u,vN1 \leq u,v \leq N.

The constraints for each subtask are as follows:

Subtask ID Points Constraints
11 00 Sample
22 77 N=2N=2
33 88 N100N \leq 100D=1D=1
44 1515 N1000N \leq 1000D=1D=1
55 D=1D=1
66 2020 N1000N \leq 1000D105D \leq 10^5
77 D105D \leq 10^5
88 1515 No special constraints.

Translated by ChatGPT 5