Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3 7 8 QAQ has a tree with n vertices. Initially, all vertices are white. There are two chess pieces called PA and PB on
QAQ has a tree with n
vertices. Initially, all vertices are white.
There are two chess pieces called PA
and PB
on the tree. PA
and PB
are initially located on vertices a
and b
respectively. In one step, QAQ will do the following in order:
Move PA
to a neighboring vertex. If the target vertex is white, this vertex will be painted red.
Move PB
to a neighboring vertex. If the target vertex is colored in red, this vertex will be painted blue.
Initially, the vertex a
is painted red. If ab
the vertex a
is painted blue instead. Note that both the chess pieces must be moved in each step. Two pieces can be on the same vertex at any given time.
QAQ wants to know the minimum number of steps to paint all vertices blue.
Input
Each test contains multiple test cases. The first line contains the number of test cases t
t
The description of the test cases follows.
The first line of each test case contains one integer n
n
The second line of each test case contains two integers a
and b
abn
Then n
lines follow, each line contains two integers xi
and yi
xiyin
indicating an edge between vertices xi
and yi
It is guaranteed that these edges form a tree.
It is guaranteed that the sum of n
over all test cases does not exceed
Output
For each test case, output the minimum number of steps to paint all vertices blue.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started