#P9316. [EGOI 2021] Double Move / 二选一游戏

[EGOI 2021] Double Move / 二选一游戏

Background

Day 2 Problem D.

The statement is translated from EGOI2021 doublemove.

Problem Description

Alice and Bob are playing a game, and Claire is helping them. There are nn stones, numbered from 11 to nn. The game has three phases.

In the first phase, Alice and Bob take turns, with Alice going first. In each turn, a player announces which stone they are going to take, but they do not directly specify a single stone. Instead, they give two options. The two options may be the same. They may also mention stones that have already been mentioned before. No stones are taken in the first phase—the players only announce their intentions for the second phase. The first phase ends after n+1n+1 announcements.

Here is an example of the first phase when n=3n=3:

  1. Alice: “I will take 11 or 33.”
  2. Bob: “I will take 22 or 22.”
  3. Alice: “I will take 33 or 22.”
  4. Bob: “I will take 11 or 33.”

In the second phase, for each of the n+1n+1 announcements, Claire chooses one of the two options by saying “former” or “latter”. We call the sequence of Claire’s n+1n+1 choices a plan. It can be seen that there are exactly 2222=2n+12\cdot 2\cdot 2\cdot\cdots\cdot 2=2^{n+1} possible plans. (Even if in some announcements the two options are exactly the same, we still consider choosing “former” and choosing “latter” as different plans.)

Here is one of the 1616 possible plans that Claire might choose:

  1. “Former”: Alice will take 11.
  2. “Former”: Bob will take 22.
  3. “Latter”: Alice will take 22.
  4. “Former”: Bob will take 11.

In the third phase, Alice and Bob start taking stones according to Claire’s choices. The first player who cannot perform their required move—because that stone has already been taken—loses the game. Note that there are nn stones and n+1n+1 moves, so one player will inevitably lose in the end.

In the example above, Alice first takes 11. Bob then takes 22. Alice wants to take 22 next, but it has already been taken, so Alice loses and Bob wins.

You are given the integer nn, and the game state at some moment during the first phase: a sequence of kk announcements that have already been made. These announcements may be completely arbitrary.

From this point on, Alice and Bob will play optimally, meaning:

No matter how Alice and Bob play, Claire chooses uniformly at random from the 2n+12^{n+1} possible plans. Alice and Bob know this, so when they play optimally, each of them tries to minimize the number of plans in which they lose.

Assuming Alice and Bob continue the game as described above, compute, for each of them, the number of plans under which they win the game.

Input Format

The first line contains two integers n,kn,k: the number of stones and the number of announcements already made.

The next kk lines describe the announcements in order. Each line contains two integers: the indices of the two stones (in 1n1\sim n and not necessarily distinct).

Note that when k<n+1k < n+1, the player to make the next announcement is determined by the parity of kk.

Output Format

Print one line with two integers: the number of plans in which Alice wins, and the number of plans in which Bob wins, assuming both continue the game optimally as described above.

Note that the sum of these two integers should be 2n+12^{n+1}.

3 4
1 3
2 2
3 2
1 3
4 12
2 0
4 4

Hint

Explanation for Sample 11.

This sample is the same as the one given in the Description. No further announcements need to be made, so we only need to count how many plans make Alice win and how many plans make Bob win. Alice wins if and only if Claire chooses 11 in the first step, and chooses 33 in the third step. All other plans make Alice lose.


Explanation for Sample 22.

If Alice first announces (1,1)(1,1), Bob will announce (2,2)(2,2). No matter what Alice announces next, she will lose, because Claire will choose 11 in the first step and 22 in the second step, and then there will be no remaining stone for Alice to take in the third step. However, this is not Alice’s optimal first move: she should instead announce (1,2)(1,2) first. Then, no matter how Bob and Alice announce in the last two steps, they will each win 44 out of the 88 plans.


Constraints

For all data, 1n351\le n\le 35, 0kn+10\le k\le n+1.

  • Subtask 1 (1515 points): n4n\le 4.
  • Subtask 2 (3434 points): n10n\le 10.
  • Subtask 3 (2020 points): n25n\le 25.
  • Subtask 4 (1010 points): k=0k=0.
  • Subtask 5 (2121 points): no additional constraints.

Translated by ChatGPT 5