#P14521. 【MX-S11-T2】加减乘除
【MX-S11-T2】加减乘除
Background
Imagine a Future Rose - 20 Levent / Xingchen.
Problem Description
You are given a tree with nodes, numbered from to . The root is node . Each node has an operator (either plus or minus) and a number . Each edge has an interval .
You start at node with a number in your hand, and you need to perform the following process:
- Suppose you are at node . You change the number in your hand from to .
- You may choose to end the process at node , or you may choose a child node . Suppose the interval on the edge connecting and is . You must satisfy , then move to and repeat these two steps.
You are given queries. In each query, you are given the initial value of in your hand. You need to answer how many nodes you can end the process at.
Input Format
The first line contains two integers .
The next lines: in the -th line there are three integers , meaning the parent of node is , and the interval on the edge connecting them is .
The next lines: in the -th line there is a character and an integer .
The next lines: each line contains an integer .
Output Format
Output lines, each line contains one integer, representing the answer.
5 5
1 4 7
1 5 8
2 3 4
2 1 6
+ 3
- 2
+ 1
- 4
+ 7
1
2
3
4
5
3
5
5
4
2
Hint
Sample Explanation #1
When , you can end the process at nodes .
When , you can end the process at nodes .
When , you can end the process at nodes .
When , you can end the process at nodes .
When , you can end the process at nodes .
Sample #2
See and in the contestant directory.
This sample satisfies the constraints of test points .
Sample #3
See and in the contestant directory.
This sample satisfies the constraints of test points .
Sample #4
See and in the contestant directory.
This sample satisfies the constraints of test points .
Sample #5
See and in the contestant directory.
This sample satisfies the constraints of test point .
Sample #6
See and in the contestant directory.
This sample satisfies the constraints of test points .
Constraints
There are test points in this problem, each worth points.
For all testdata, it is guaranteed that:
- .
- .
- .
- .
- .
- .
::cute-table{tuack}
| Test Point ID | Special Property | ||
|---|---|---|---|
| None | |||
| A | |||
| ^ | B | ||
| C | |||
| None | |||
- Special Property A: For all , .
- Special Property B: For all , and . Also, for all , , and .
- Special Property C: For all , .
Translated by ChatGPT 5