CF1381D The Majestic Brown Tree Snake

Description

There is an undirected tree of $ n $ vertices, connected by $ n-1 $ bidirectional edges. There is also a snake stuck inside of this tree. Its head is at vertex $ a $ and its tail is at vertex $ b $ . The snake's body occupies all vertices on the unique simple path between $ a $ and $ b $ . The snake wants to know if it can reverse itself — that is, to move its head to where its tail started, and its tail to where its head started. Unfortunately, the snake's movements are restricted to the tree's structure. In an operation, the snake can move its head to an adjacent vertex not currently occupied by the snake. When it does this, the tail moves one vertex closer to the head, so that the length of the snake remains unchanged. Similarly, the snake can also move its tail to an adjacent vertex not currently occupied by the snake. When it does this, the head moves one unit closer to the tail. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1381D/96ecf077c76764b66ae525ead715fd9f4da27486.png) Let's denote a snake position by $ (h,t) $ , where $ h $ is the index of the vertex with the snake's head, $ t $ is the index of the vertex with the snake's tail. This snake can reverse itself with the movements $ (4,7)\to (5,1)\to (4,2)\to (1, 3)\to (7,2)\to (8,1)\to (7,4) $ . Determine if it is possible to reverse the snake with some sequence of operations.

Input Format

N/A

Output Format

N/A

Explanation/Hint

The first test case is pictured above. In the second test case, the tree is a path. We can show that the snake cannot reverse itself. In the third test case, we can show that the snake cannot reverse itself. In the fourth test case, an example solution is: $ (15,12)\to (16,11)\to (15,13)\to (10,14)\to (8,13)\to (4,11)\to (1,10) $ $ \to (2,8)\to (3,4)\to (2,5)\to (1,6)\to (4,7)\to (8,6)\to (10,5) $ $ \to (11,4)\to (13,8)\to (14,10)\to (13,15)\to (11,16)\to (12,15) $ .