#P10603. BZOJ4372 烁烁的游戏
BZOJ4372 烁烁的游戏
Background
This problem comes from the original BZOJ. We acknowledge that the statement and original testdata are copyrighted by the original BZOJ or the problem author who authorized BZOJ to use it. If you are the copyright holder and believe we have infringed your rights, please contact us.
Shuoshou really likes climbing trees, which scares the Pipishu (pípíshǔ) on the tree.
You are given a tree with nodes, where all edge weights are . Initially, there are no Pipishu on the tree.
Each time, Shuoshou jumps to a node and attracts Pipishu to each node whose distance to him is at most . Since the Pipishu are attracted by Shuoshou, they will stay at their nodes and never move.
Shuoshou is curious: at the current moment, how many of his good friends—Pipishu—are on node .
Problem Description
The background can be abstracted into the following problem:
Given a tree with nodes, where all edge weights are , and the initial node weights are all . Perform operations:
- : query the node weight of node .
- : add to the node weight of every node whose distance to node is at most .
Input Format
The first line contains two positive integers .
The next lines each contain two positive integers , indicating that there is an edge between and .
The next lines each describe one of the two operations above.
Output Format
For each operation, output the current node weight of node .
7 6
1 2
1 4
1 5
2 3
2 7
5 6
M 1 1 2
Q 5
M 2 2 3
Q 3
M 1 2 1
Q 2
2
3
6
Hint
For all data, it is guaranteed that and . Note that is not necessarily positive.
Translated by ChatGPT 5