Double Move
Time limit5sMemory limit512 MB
Given n stones and some already declared pairs of candidate stones, count the scenarios in which Alice and Bob each win when both play optimally.
- Level
Hard9 of 10
- Topics
- Game theory, Combinatorics, Math
- Solved
- No attempts yet
Problem
Alice and Bob are playing a game, and Claire is helping them. There are stones, numbered from to . The game consists of three phases.
In the first phase, Alice and Bob make alternating moves. Alice moves first. In each move, a player declares their intention to take a stone, but instead of naming the stone, they name two options. The two options may be the same. A player may also name stones that were already named in earlier moves. No stones are actually taken in this phase. The first phase ends when declarations have been made.
In the second phase, Claire picks one of the two options in each of the declarations by saying "first" or "second". Each sequence of choices made by Claire is a scenario. There are exactly scenarios. Even when the two options in a declaration are the same, choosing "first" and choosing "second" count as different scenarios.
In the third phase, Alice and Bob take stones according to Claire's choices. The first player who cannot make the required move, because the stone is already taken, loses the game. Since there are stones and moves, one of the players must lose.
Alice and Bob know that Claire picks each of the scenarios with equal probability. When playing optimally, each player tries to minimize the number of scenarios in which they lose.
You are given and the state of the game partway through the first phase: a sequence of declarations that have already been made. These declarations can be arbitrary. From this point on, Alice and Bob play optimally as described above. For each player, find the number of scenarios in which that player wins.
Input
The first line contains two space-separated integers and (, ): the number of stones and the number of declarations already made.
Each of the next lines contains two space-separated integers, the numbers of the two stones in one declaration, in the order they were made. Both numbers are between and , inclusive, and they need not be distinct.
When , the parity of determines which player makes the next declaration.
Output
Print one line with two space-separated integers: the number of scenarios in which Alice wins and the number of scenarios in which Bob wins, assuming both players play the rest of the game optimally. The sum of the two numbers must equal .
Hint
The first sample matches the example in the statement. No declarations remain, so we only count Claire's choices that lead to an Alice win and to a Bob win. Alice wins if Claire picks stone for her first move and stone for her second move, and loses in all other cases.
In the second example, if Alice starts by declaring "1 1", Bob answers "2 2", and whatever Alice declares third, she loses. Claire can pick stone for the first move and stone for the second, leaving no stone for Alice's third move. This is not Alice's best opening. She should declare "1 2" instead. Then, no matter how Bob and Alice play afterward, each of them wins in of the scenarios.