Problem E
Evading a Monster
A monster is chasing you in a tree with
You are trying to keep away from the monster, while performing as few moves as possible. A move means moving from a vertex to an adjacent vertex. Before each of the monster’s moves, you may make any number of moves.
What is the minimal number of moves you have to make?
Input
The first line contains the integers
The next
The final line contains the
Output
Output a single integer, the minimal number of moves you have to perform to avoid the monster.
If avoiding the monster is impossible, output -1.
Scoring
Your solution will be tested on a set of test groups, each worth a number of points. To get the points for a test group you need to solve all test cases in the test group.
|
Group |
Points |
Constraints |
|
|
|
|
|
|
|
Each vertex has degree at most |
|
|
|
No additional constraints. |
| Sample Input 1 | Sample Output 1 |
|---|---|
4 2 1 2 2 3 1 4 2 3 |
-1 |
| Sample Input 2 | Sample Output 2 |
|---|---|
5 7 1 2 2 3 1 4 2 5 2 3 2 5 2 1 4 |
5 |
