CF2230F.Game on Growing Tree

省选/NOI-

通过率:0%

时间限制:6.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Consider a game for two players: Alice and Bob. They have a tree TT; initially, every vertex of this tree is white. Alice and Bob take turns: Alice goes first, then Bob, then Alice again, then Bob again, and so on.

During Alice's first turn, she has to choose a vertex and put a chip in it, then paint the chosen vertex red. During every turn except for the first one, Alice has to move the chip into an adjacent white vertex and paint that vertex red. If, at the start of Alice's turn, there are no white vertices adjacent to the vertex with the chip, the game ends.

During each of Bob's turns, he has to choose a white vertex and paint it blue. If there are no white vertices in the tree at the start of Bob's turn, the game ends.

The final score of the game is the number of red vertices. Alice wants to maximize the score, Bob wants to minimize it. Both players play optimally.

This is the description of the game. The statement of the problem follows.

You are given a tree, initially consisting of only one vertex numbered 11. Then, qq queries are performed; during the ii-th query, a new vertex is added to the tree; this new vertex gets the number (i+1)(i+1) and is connected to the vertex viv_i by an edge. After each query, you have to print the final score of the game if Alice and Bob play on the current tree.

考虑一个双人游戏:爱丽丝(Alice)和鲍勃(Bob)。他们拥有一棵树 TT;初始时,该树的每个顶点均为白色。爱丽丝与鲍勃轮流进行操作:爱丽丝先手,随后鲍勃,接着爱丽丝,再鲍勃,依此类推。

在爱丽丝的第一回合中,她必须选择一个顶点,并在该顶点上放置一枚棋子,然后将所选顶点涂成红色。在除第一回合外的每一回合中,爱丽丝必须将棋子移动至一个与当前棋子所在顶点相邻的白色顶点,并将该顶点涂成红色。若在爱丽丝回合开始时,棋子所在顶点周围不存在任何白色顶点,则游戏结束。

在鲍勃的每一回合中,他必须选择一个白色顶点并将其涂成蓝色。若在鲍勃回合开始时,树中已无白色顶点,则游戏结束。

游戏的最终得分为红色顶点的数量。爱丽丝希望最大化该得分,而鲍勃希望最小化该得分。双方均以最优策略进行游戏。

以上即为该游戏的规则描述。问题陈述如下:

给定一棵初始仅含一个编号为 11 的顶点的树。随后执行 qq 次查询;在第 ii 次查询中,向树中添加一个新顶点;该新顶点编号为 (i+1)(i+1),并通过一条边与顶点 viv_i 相连。每次查询后,你需要输出:若爱丽丝与鲍勃在当前树上进行上述游戏,其最终得分是多少。

输入格式

The first line contains one integer qq (1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the number of queries.

The second line contains qq integers v1,v2,…,vqv_1, v_2, \dots, v_q (1≤vi≤i1 \le v_i \le i), where viv_i is the vertex that gets connected with the vertex (i+1)(i+1) during the ii-th query.

第一行包含一个整数 qq(1≤q≤2⋅1051 \le q \le 2 \cdot 10^5)—— 查询次数。

第二行包含 qq 个整数 v1,v2,…,vqv_1, v_2, \dots, v_q(1≤vi≤i1 \le v_i \le i),其中 viv_i 表示在第 ii 次查询中与顶点 (i+1)(i+1) 相连的顶点。

输出格式

Print qq integers; the ii-th of these integers should be the score if Alice and Bob play on the tree that you get after processing the ii-th query.

输出 qq 个整数;其中第 ii 个整数应为 Alice 和 Bob 在处理完第 ii 个查询后所得树上进行游戏时的得分。

输入输出样例

  • 输入#1

    9
    1 1 3 3 1 2 1 2 8

    输出#1

    1 2 2 2 2 2 2 3 3

说明/提示

null

输入解题思路,AI测评打分。不知道怎么写?

首页