Daylight
Time limit13sMemory limit512 MB
Given an unrooted tree and online daily queries (u, v, w), count the vertices within w edges of u or v, with each query decoded from the previous answer.
- Level
Hard8 of 10
- Topics
- Tree, Divide and conquer, Implementation
- Solved
- No attempts yet
Statement
Noah owns an unrooted tree with vertices numbered from 1 to . Every morning Noah picks two vertices and to receive influence from daylight. The influence spreads through the edges, but it disappears once it has passed through more than edges.
For each day, count the vertices influenced by the daylight. The input is encrypted, so your solution must work online.
Input
The first line contains , the number of test cases.
For each test case, the first line contains and . Each of the next lines contains and , an edge between vertices and .
Let be the answer to the previous day. At the start of each test case, is 0. Each of the next lines contains , , and , and the actual values are
Constraints: , , , .
No more than 10 test cases fail to satisfy , and the input file is at most 32 MiB.
Output
For each day, print the answer on one line.
The output file is at most 7 MiB.
Hint
The decrypted values are as follows. Day 1: , , . Day 2: , , . Day 3: , , . Day 4: , , . Day 5: , , .