#Lutece0823. Little Wish ~lyrical step~
Little Wish ~lyrical step~
Migrated from Lutece 823 Little Wish ~lyrical step~
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
children are living in a tree with exactly nodes, on each node there lies either a boy or a girl.
A girl is said to be protected, if the distance between the girl and her nearest boy is no more than .
You want to do something good, so that each girl on the tree will be protected. On each step, you can choose two nodes, and swap the children living on them.
What is the minimum number of steps you have to take to fulfill your wish?
Input
The first line has a number () , indicating the number of test cases.
In a case, the first line contain two number (), (), Which means the number of the node and the distance between the girls and boys.
The next lines contains number. The number means the node contains a girl or a boy. ( means girl means boy), The follow lines contains , , , means a edge connect node and node, and the length of the edge is ().
Output
For every case, you should output Case #t:
at first, without quotes.
The is the case number starting from .
Then follows the answer, meas you can't comlete it, and others means the minimum number of the times.
Samples
1
3 1
0 0 1
1 2 1
1 3 1
Case #1: 1
Resources
2013 ACM/ICPC Asia Regional Chengdu Online