PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#LCA0000025. Alyona và một cây (Alyona and a Tree)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Alyona và một cây (Alyona and a Tree)
Alyona and a Tree
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Alyona has a tree of vertices rooted at vertex . Each vertex has a nonnegative integer . Every parent-child edge has a positive length.
For each vertex , count vertices that are strict descendants of ( and the root-to- path passes through ) such that the weighted distance from to is at most .
The limit is the descendant vertex's value , not .
Input
- The first line contains .
- The second line contains values .
- For each , one line contains , the parent of and the length of its parent edge.
Output
Print integers; value counts strict descendants satisfying the distance limit.
Subtasks
- Subtask 1 (20 points): ; ; ; (các cạnh tạo thành cây gốc ); .
- Subtask 2 (30 points): ; ; ; (các cạnh tạo thành cây gốc ); .
- Subtask 3 (50 points): ; ; (các cạnh tạo thành cây gốc ); .
Examples
Input
5
2 5 1 4 6
1 7
1 1
3 5
3 6
Output
1 0 1 0 0
Explanation
Vertex has exactly one strict descendant meeting that descendant’s own distance limit. Vertex also has one such descendant; the other vertices have none.