CF813C.The Tag Game
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of n vertices. Vertex 1 is the root of the tree.
Alice starts at vertex 1 and Bob starts at vertex x (x ≠ 1). The moves are made in turns, Bob goes first. In one move one can either stay at the current vertex or travel to the neighbouring one.
The game ends when Alice goes to the same vertex where Bob is standing. Alice wants to minimize the total number of moves and Bob wants to maximize it.
You should write a program which will determine how many moves will the game last.
爱丽丝玩腻了按常规规则进行的“捉人”游戏,于是她向鲍勃提出了一点小修改。现在,游戏将在一棵包含 n 个顶点的无向有根树上进行,其中顶点 1 是树的根。
爱丽丝从顶点 1 出发,鲍勃从顶点 x(x=1)出发。双方轮流行动,鲍勃先手。在一次行动中,玩家可以选择停留在当前顶点,或移动到一个相邻顶点。
当爱丽丝移动到鲍勃当前所在的顶点时,游戏结束。爱丽丝希望最小化总行动次数,而鲍勃则希望最大化该次数。
你需要编写一个程序,确定游戏将持续多少次行动。
输入格式
The first line contains two integer numbers n and x (2 ≤ n ≤ 2·105, 2 ≤ x ≤ n).
Each of the next n - 1 lines contains two integer numbers a and b (1 ≤ a, b ≤ n) — edges of the tree. It is guaranteed that the edges form a valid tree.
第一行包含两个整数 n 和 x(2≤n≤2⋅105,2≤x≤n)。
接下来的 n−1 行每行包含两个整数 a 和 b(1≤a,b≤n),表示树的一条边。保证这些边构成一棵合法的树。
输出格式
Print the total number of moves Alice and Bob will make.
输出爱丽丝和鲍勃总共将进行的移动次数。
输入输出样例
输入#1
4 3 1 2 2 3 2 4
输出#1
4
输入#2
5 2 1 2 2 3 3 4 2 5
输出#2
6
说明/提示
In the first example the tree looks like this:

The red vertex is Alice's starting position, the blue one is Bob's. Bob will make the game run the longest by standing at the vertex 3 during all the game. So here are the moves:
B: stay at vertex 3
A: go to vertex 2
B: stay at vertex 3
A: go to vertex 3
In the second example the tree looks like this:

The moves in the optimal strategy are:
B: go to vertex 3
A: go to vertex 2
B: go to vertex 4
A: go to vertex 3
B: stay at vertex 4
A: go to vertex 4
在第一个例子中,树的结构如下:

红色顶点是 Alice 的起始位置,蓝色顶点是 Bob 的起始位置。Bob 通过在整个游戏中始终停留在顶点 3 来使游戏持续时间最长。因此各步操作如下:
B:停留在顶点 3
A:移动到顶点 2
B:停留在顶点 3
A:移动到顶点 3
在第二个例子中,树的结构如下:

最优策略下的操作序列为:
B:移动到顶点 3
A:移动到顶点 2
B:移动到顶点 4
A:移动到顶点 3
B:停留在顶点 4
A:移动到顶点 4
输入解题思路,AI测评打分。不知道怎么写?