Star Trek
Time limit1sMemory limit32 MB
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 planets, numbered from to . Some planets are connected by space tunnels. A starship can fly through a space tunnel in both directions very fast. There are exactly space tunnels, and any planet in the Federation can reach any other planet through them.
There are additional parallel universes. Each one is an exact copy of our universe, with the same planets and space tunnels. They are numbered from to , and our universe is number . Planet in universe is written . Travel between universes uses dimension portals. For every (), exactly one portal is placed that flies from to , where .
After all portals are placed, the starship Batthyány begins its maiden voyage, orbiting . 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 has been visited, neither of them goes back there, though planet 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 (), the th portal connects a different pair of planets in the two placements, that is, or differs. Give the answer modulo .
Input
The first line contains two integers and . Each of the next lines contains two integers and , meaning that and are connected by a space tunnel for every ().
Output
Print one integer: the number of portal placements where Captain Ágnes wins, modulo .
Constraints
Hint
There is only 1 portal, so there are different placements. The following 4 placements are the ones where the Captain wins.
