304263: CF813C. The Tag Game

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

The Tag Game

题意翻译

题意: 有一颗以1为根,节点数为n的树,A在1号点,B在x号点,A,B交替行动,A的目标是行动次数尽量少,B的目标是行动次数尽量多,问在这种情况下,行动的次数. 输入数据: 第一行两个整数n,x. 接下来n-1行<x,y>,表示x与y之间有一条连边. 输出数据: 一个整数,行动的次数. 数据范围: n:[2,2e5]

题目描述

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.

输入输出格式

输入格式


The first line contains two integer numbers $ n $ and $ x $ ( $ 2<=n<=2·10^{5} $ , $ 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.

输出格式


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: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF813C/b7ec0a99b40c82b622ba7707f0f0b2d0e630852a.png)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: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF813C/67357a90193bb980ddc9f6e8d8aabc3f3d4836ca.png)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

Input

题意翻译

题意: 有一颗以1为根,节点数为n的树,A在1号点,B在x号点,A,B交替行动,A的目标是行动次数尽量少,B的目标是行动次数尽量多,问在这种情况下,行动的次数. 输入数据: 第一行两个整数n,x. 接下来n-1行<x,y>,表示x与y之间有一条连边. 输出数据: 一个整数,行动的次数. 数据范围: n:[2,2e5]

加入题单

上一题 下一题 算法标签: