#P8575. 「DTOI-2」星之河

「DTOI-2」星之河

Background

The stars are sparse as the river’s shadow turns, the frost is heavy and the moonlight stands alone.

Problem Description

The ruler of the stars has a star chart, which can be abstracted as a tree rooted at node 11. Each node ii on the tree has a red star and a blue star, with brightness denoted by Redi\text{Red}_i and Bluei\text{Blue}_i.

Now, the ruler of the stars wants to know, for each node xx, how many nodes in its subtree (excluding the node itself) satisfy: their red star brightness is less than or equal to the red star brightness of xx, and their blue star brightness is less than or equal to the blue star brightness of xx.

You need to output the answer for each node in increasing order of node index. To reduce the amount of output, if the answer is 00, you do not need to output it.

Input Format

The first line contains an integer nn.

The next n1n - 1 lines each contain two positive integers u,vu, v, indicating that the tree has an edge (u,v)(u, v).

The next nn lines each contain two integers, representing Redi\text{Red}_i and Bluei\text{Blue}_i.

Output Format

For each node whose answer is non-zero, output one line containing an integer, which is the answer for that node.

10
2 1
3 1
4 3
5 1
6 4
7 2
8 2
9 4
10 3
3 1
2 4
-3 3
4 -2
-2 3
-3 -6
-5 -1
-4 -7
-5 -1
-7 -7
5
2
3
1

Hint

Sample Explanation

For node 11, the children that are less than or equal to it are 6,7,8,9,106, 7, 8, 9, 10, so output 55.
For node 44, the child that is less than or equal to it is 66, so output 11.
For nodes 55 to 1010, there are no children that are less than or equal to them, so do not output anything.

Constraints

Subtask\textbf{Subtask} nn\le Special Property Total Score
11 10001000 None 1010
22 5×1045\times 10^4 2020
33 10510^5 200Redi,Bluei200-200\le \text{Red}_i, \text{Blue}_i \le 200
44 2×1052\times 10^5 The tree is a chain
55 None 3030

For all testdata, it is guaranteed that n2×105n \le 2\times 10^5 and 109Redi,Bluei109-10^9 \le \text{Red}_i, \text{Blue}_i \le 10^9.

Translated by ChatGPT 5