Problem D
The Escape
You have all heard of the story of the three little pigs. However, this time they’re facing another predicament yet again!
The three pigs brought a bunch of their pig friends into a
tree, which is a connected undirected graph with
Of course, the surviving pigs now wants to escape. A pig is
considered to have escaped if he is on any leaf vertex (a
vertex connected to only one edge). A pig currently on vertex
Input
The first line of the input contains two integers
The last line of the input contains
Output
Output
Sample Input 1 | Sample Output 1 |
---|---|
6 3 0 1 1 2 2 3 2 4 1 5 1 2 5 |
0 |
Sample Input 2 | Sample Output 2 |
---|---|
11 3 0 1 1 2 0 3 3 4 4 5 5 6 0 7 7 8 8 9 9 10 1 3 9 |
3 |