#P3258. [JLOI2014] 松鼠的新家
[JLOI2014] 松鼠的新家
Description
The squirrel’s new home is a tree. It was just renovated a few days ago. The new home has rooms and edges connecting them. Every pair of rooms is reachable, and the route between any two rooms is unique. Oh my, he really lives on a "tree".
The squirrel wants to invite Winnie the Pooh to visit and specifies a visiting itinerary. He hopes Winnie will visit in order: first , then , …, and finally . However, this would cause revisiting many rooms, and the lazy Winnie keeps refusing. But the squirrel tells him that each time he arrives at a room, he can take one candy from that room.
Winnie is a glutton, so he agrees at once. Now the squirrel wants to know, to ensure Winnie always has a candy to eat, how many candies at minimum he needs to place in each room.
Since the last room in the itinerary is the dining room, where a feast has been prepared, when Winnie arrives at the dining room at the end of the tour, he does not need to take a candy there.
Input Format
The first line contains a positive integer , the number of rooms. The second line contains positive integers describing in order.
The next lines each contain two positive integers , indicating that rooms labeled and are connected by an edge.
Output Format
Output lines. On the -th line, output the minimum number of candies that must be placed in the room labeled so that Winnie always has a candy to eat.
5
1 4 5 3 2
1 2
2 4
2 3
4 5
1
2
1
2
1
Hint
For all testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号