#LCA0000083. Ngôi nhà mới của sóc (Squirrel’s New Home)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Ngôi nhà mới của sóc (Squirrel’s New Home)
Squirrel’s New Home
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
A squirrel lives in a house with rooms connected by corridors forming a tree. A visitor follows the itinerary , using the unique route between consecutive rooms. The visitor takes one candy upon first arriving at and whenever entering another room along the walk. No extra candy is taken at a junction between consecutive itinerary segments. At the final destination , no candy is taken on the final arrival because dinner is served there. Find the minimum candies to put in each room.
Input
First line: . Second line: room labels . Next lines: edges .
Output
Print lines; line contains the candies required in room .
Subtasks
-
Subtask 1 (20 points): ; ; the itinerary has positions and the tree has edges, edges form a tree.
-
Subtask 2 (30 points): ; ; the itinerary has positions and the tree has edges, edges form a tree.
-
Subtask 3 (50 points): ; ; the itinerary has positions and the tree has edges, edges form a tree.
Examples
Input
5
1 4 5 3 2
1 2
2 4
2 3
4 5
Output
1
2
1
2
1
Explanation
The actual walk is . Rooms and each require two candies; none is taken on the final arrival at room .