#P17307. [ICPC 2026 Xi'an I] Zebra Crossing

    ID: 17198 Type: RemoteJudge 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 9 Uploaded By: Tags>模拟贪心广度优先搜索 BFS深度优先搜索 DFS树形 DPICPC2026省赛/邀请赛西安

[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 nn nodes. The ii-th edge connects node uiu_i and node viv_i. Each node is colored either black or white, described by a binary string ss of length nn:

  • If si=0s_i = \texttt{0}, the color of node ii is black.
  • If si=1s_i = \texttt{1}, the color of node ii is white.

Yuki has a jumping ability kk, which means that when she is at node xx, she can jump to any node yy such that dist(x,y)≤k\text{dist}(x, y) \le k. Here, dist(x,y)\text{dist}(x, y) denotes the number of edges on the simple path between node xx and node yy.

Next, Yuki will perform n−1n-1 rounds of jumping on the zebra crossing. In the ii-th round, Yuki starts at node 11 and wants to reach node i+1i+1 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 tt (1≤t≤105)(1 \le t \le 10^5), representing the number of test cases.

For each test case:

  • The first line contains two positive integers n,kn, k (1≤n≤5⋅105, 1≤k≤n)(1 \le n \le 5\cdot10^5,\ 1 \le k \le n).
  • The second line contains a binary string ss of length nn (si∈{0,1})(s_i \in \{\texttt0, \texttt1\}).
  • The next n−1n-1 lines each contain two positive integers ui,viu_i, v_i (1≤ui,vi≤n, ui≠vi)(1 \le u_i, v_i \le n,\ u_i \ne v_i).

It is guaranteed that the sum of nn over all test cases does not exceed 5⋅1055\cdot10^5.

输出格式

For each test case, output a single line containing n−1n-1 integers, where the ii-th integer represents the minimum number of times Yuki lands on a black node during the ii-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 11-st round of jumping, one valid sequence of visited nodes is 1,21, 2.
  • For the 44-th round of jumping, one valid sequence of visited nodes is 1,3,51, 3, 5.

For the second test case:

  • For the 44-th round of jumping, one valid sequence of visited nodes is 1,51, 5.
  • For the 77-th round of jumping, one valid sequence of visited nodes is 1,5,81, 5, 8.
  • For the 88-th round of jumping, one valid sequence of visited nodes is 1,4,91, 4, 9.