#ds1002. 天天爱跑步
天天爱跑步
Daily Running
Problem Source
NOIP 2016
Problem Description
Little C thinks running is a lot of fun, so he decides to make a game called "Daily Running". "Daily Running" is a nurturing game in which players must log in on time every day to complete a check-in task.
The game map can be viewed as a tree with nodes and edges, where each edge connects two nodes and any two nodes are reachable from each other by a path. The nodes are numbered to (consecutive positive integers).
There are players. The -th player has start point and end point . When the daily check-in task begins, all players start simultaneously from their own start at second , running non-stop along the shortest path toward their own end at a speed of one edge per second. A player finishes the check-in task once they reach their end. (Because the map is a tree, each player's path is unique.)
Little C wants to know the game's activity level, so he places an observer at each node. The observer at node chooses to observe players at second . A player is observed by this observer if and only if the player also arrives at node exactly at second . Little C wants to know how many players each observer will observe.
Note: A player ends the game upon reaching their end, and cannot wait around to be observed later. That is, for a player whose end point is node : if they arrive at the end before second , the observer at node cannot observe them; if they arrive at node exactly at second , the observer at node can observe them.
Input Format
Read the data from standard input.
The first line contains two integers (). Here is the number of nodes in the tree (and also the number of observers), and is the number of players.
The next lines each contain two integers and , indicating an edge between node and node .
The next line contains integers, where the -th integer is , the time at which the observer at node appears.
The next lines each contain two integers and , the start and end of a player.
For all data, and are guaranteed.
Output Format
Write the output to standard output.
Output a single line of integers, where the -th integer is the number of players that the observer at node can observe.
Sample Input 1
6 3
2 3
1 2
1 4
4 5
4 6
0 2 5 1 2 3
1 5
1 3
2 6
Sample Output 1
2 0 0 1 1 1
Sample Input 2
5 3
1 2
2 3
2 4
1 5
0 1 0 3 0
3 1
1 4
5 5
Sample Output 2
1 2 1 0 1
Sample Explanation
- For node 1, , so only players starting at node 1 are observed. Players 1 and 2 start at node 1, so 2 players are observed.
- For node 2, no player is at this node at second 2, so 0 players are observed.
- For node 3, no player is at this node at second 5, so 0 players are observed.
- For node 4, player 1 is observed, so 1 player is observed.
- For node 5, player 1 is observed, so 1 player is observed.
- For node 6, player 3 is observed, so 1 player is observed.