#LCA0000080. Đếm số đường đi qua mỗi đỉnh (Counting Paths)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm số đường đi qua mỗi đỉnh (Counting Paths)
Counting Paths
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an undirected tree with vertices and journeys. Each journey follows the unique simple path from to , including both endpoints. For every vertex , count how many journeys contain . A journey with contains just that vertex.
Input
The first line contains . Each of the next lines contains an undirected edge . Each of the final lines contains a journey .
Output
Print integers on one line. The -th integer counts journeys passing through vertex .
Subtasks
-
Subtask 1 (20 points): ; ; ; edges form an undirected tree; paths include endpoints.
-
Subtask 2 (30 points): ; ; ; edges form an undirected tree; paths include endpoints.
-
Subtask 3 (50 points): ; ; ; edges form an undirected tree; paths include endpoints.
Examples
Input
5 3
1 2
1 3
3 4
3 5
1 3
2 5
1 4
Output
3 1 3 1 1
Explanation
Vertices and occur in all three paths. Each of vertices occurs in exactly one path.