公式

F - Subtree Reversi 解説 by evima


Assuming the root’s depth to be \(0\), when a stone is placed on a vertex of even depth, it will eventually be of the player’s color, and when placed on a vertex of odd depth, it will be of the opponent’s color. Therefore, if we let \(a\) and \(b\) be the number of vertices of odd depth where Alice and Bob will place stones during the procedure, respectively, Alice’s score will be \((N+1)/2-a+b\), and it is seen that Alice should minimize \(a\) and Bob should minimize \(b\).

Next, we color the vertices of even depth red and those of odd depth blue.

We then decompose the tree into several groups according to the following rules:

  1. If there is a red vertex that is a leaf, it is considered as an independent group.
  2. Excluding vertices that have already been divided into groups, look at the blue vertices whose parent has more than one child. The subtree rooted at the vertex with the smallest subtree size becomes a group.
  3. Repeat the above until all vertices belong to a group. Then, add a virtual blue vertex as the parent of the root.

At this point, we call the number of blue vertices belonging to each group the “cost”. Each group has an odd number of vertices, and when vertices are taken in order within a group, their colors will be blue → red → blue… (except for a group consisting only of red). Therefore, this game can be interpreted as taking turns choosing a group with a fixed cost and paying that cost to pass the turn to the opponent.

In reality, the division of groups may change from what was described earlier depending on the order in which vertices are chosen in the tree, but it can be shown that such a choice does not benefit (described later). Also, considering the consistency with the original game, for the order in which groups are chosen, a group formed from a subtree rooted at a deeper vertex must be chosen earlier. However, since a group formed from a subtree on the descendant side always has a smaller cost than a group on the ancestor side, as long as they are chosen in ascending order of cost, it is guaranteed to correspond to the procedure of the game on the tree without contradiction.

Therefore, alternately taking the costs of the groups calculated as above in ascending order is optimal for both players, and the total cost will be the number of blue vertices where each player places a stone during the procedure.


[Proof that the above procedure is optimal]

We will show that, for the tree’s state at each point, when it is decomposed into groups according to the rules described above, it is optimal to take one vertex from the group with the smallest cost at that point (we will call this condition Ⓐ).

In this case, we will have the progression described earlier: for the decomposition of the given tree into groups, in ascending order of cost, the players will alternately take a vertex from the same group until there is no more vertex in that group.

We show the claim by induction from the end of the procedure.

First, when the remaining vertices were path-shaped, the only possible move satisfies the condition Ⓐ.

Next, when there were multiple vertices to choose from, consider the turn when the last move that violated the condition Ⓐ was played. For convenience, let the player who had this turn be the first player.

Let \(k\) be the cost of the group from which the player took the vertex. Also, let \(a, b, c, ...\) be the costs of the other remaining groups in ascending order. The game would progress as follows:

① When \(k>1\):

The first player’s move can be interpreted as cutting out a cost of \(1\) from the group of cost \(k\) and taking it first, resulting in groups of costs \(0\) and \(k-1\). Therefore, the subsequent progression (including this move of the first player) would be:

  • \(1 → 0 → a → b → c → k-1 → ... \)

On the other hand, if the first player had met the condition Ⓐ, it would have been:

  • \(a → b → c → k → ...\)

Thus, the increase in the cost paid by the second player is \(\pm 0\) if the first player had taken the group of cost \(k\) in the original progression, and \(-1\) if the second player had taken it, neither of which benefits the first player.

② When \(k=1\):

In this case, there is another group with a cost of \(0\), so let \(a=0\). The subsequent progression would be:

  • \(k=1 → a=0 → b → c →... \)

On the other hand, if the first player had met the condition Ⓐ, it would have been:

  • \(a=0 → k=1 → b → c →... \)

(If \(b=0\) or \(c=0\), then \(k\) appears later.) Again, in this case, the increase in the cost paid by the second player is \(\pm 0\) or \(-1\), neither of which benefits the first player.

Therefore, it has been seen that the best move for the first player here was to meet the condition Ⓐ.

One can repeat this discussion to trace back to the first move, showing that the procedure described above is optimal.

(Modified the first draft written by GPT-4.)

投稿日時:
最終更新: