381 传统题

[CF2289E] 掰手腕锦标赛 (The Problem from Silach)

时间限制
2000ms
内存限制
256MiB
登顶 / 尝试
1/ 1
难度
6
    上传者 标签CodeforcesDiv. 2树论启发式合并贪心

[CF2289E] 掰手腕锦标赛 (The Problem from Silach)

Problem Statement

nn athletes numbered 11 (strongest) to nn (weakest) participate in a single-elimination tournament of n−1n-1 matches numbered n+1n+1 to 2n−12n-1. In a match between two athletes, if their numbers differ by at least dd, the smaller number always wins; otherwise either athlete can win. Each match kk (n+1≤k≤2n−1n+1 \le k \le 2n-1) specifies two participants p1,p2<kp_1, p_2 < k (an athlete if ≤n\le n, or the winner of match pip_i if >n> n). Each 1…2n−21 \dots 2n-2 appears once.

For each athlete 1…n1 \dots n, find the maximum number of matches they can participate in.

Input

First line: tt (1≤t≤1041 \le t \le 10^4). Each test case: n,dn, d (2≤n≤2⋅105,1≤d≤n2 \le n \le 2 \cdot 10^5, 1 \le d \le n), followed by n−1n-1 lines p1,p2p_1, p_2. Sum of n≤2⋅105n \le 2 \cdot 10^5.

Output

Output nn integers for each test case.

样例

2
5 1
2 5
3 4
6 7
8 1
5 2
2 5
3 4
6 7
8 1
1 3 2 1 1
1 3 3 2 1