#P17307. [ICPC 2026 Xi'an I] Zebra Crossing
[ICPC 2026 Xi'an I] Zebra Crossing
题目描述
In front of Yuki is a strange zebra crossing.
This zebra crossing can be viewed as a tree with nodes. The -th edge connects node and node . Each node is colored either black or white, described by a binary string of length :
- If , the color of node is black.
- If , the color of node is white.
Yuki has a jumping ability , which means that when she is at node , she can jump to any node such that . Here, denotes the number of edges on the simple path between node and node .
Next, Yuki will perform rounds of jumping on the zebra crossing. In the -th round, Yuki starts at node and wants to reach node through a sequence of jumps. At the same time, Yuki wants to minimize the number of times she lands on a black node after her jumps.
You need to help Yuki find the minimum number of times she lands on a black node for each round of jumping.
输入格式
This problem contains multiple test cases.
The first line contains a positive integer , representing the number of test cases.
For each test case:
- The first line contains two positive integers .
- The second line contains a binary string of length .
- The next lines each contain two positive integers .
It is guaranteed that the sum of over all test cases does not exceed .
输出格式
For each test case, output a single line containing integers, where the -th integer represents the minimum number of times Yuki lands on a black node during the -th round of jumping.
2
5 1
01010
3 5
2 1
1 3
3 4
9 3
100010000
1 2
2 3
2 4
3 5
3 6
4 7
6 8
7 9
0 1 1 2
1 1 1 0 1 1 1 2
提示
For the first test case:
- For the -st round of jumping, one valid sequence of visited nodes is .
- For the -th round of jumping, one valid sequence of visited nodes is .
For the second test case:
- For the -th round of jumping, one valid sequence of visited nodes is .
- For the -th round of jumping, one valid sequence of visited nodes is .
- For the -th round of jumping, one valid sequence of visited nodes is .