PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000080. Đếm số đường đi qua mỗi đỉnh (Counting Paths)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Đế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 nn vertices and mm journeys. Each journey follows the unique simple path from aa to bb, including both endpoints. For every vertex vv, count how many journeys contain vv. A journey with a=ba=b contains just that vertex.

Input

The first line contains n,mn,m. Each of the next n−1n-1 lines contains an undirected edge u,vu,v. Each of the final mm lines contains a journey a,ba,b.

Output

Print nn integers on one line. The vv-th integer counts journeys passing through vertex vv.

Subtasks

  • Subtask 1 (20 points): 1≤n≤351\le n\le 35; 1≤m≤351\le m\le 35; 1≤u,v,a,b≤n1\le u,v,a,b\le n; edges form an undirected tree; paths include endpoints.

  • Subtask 2 (30 points): 1≤n≤12001\le n\le 1200; 1≤m≤12001\le m\le 1200; 1≤u,v,a,b≤n1\le u,v,a,b\le n; edges form an undirected tree; paths include endpoints.

  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤m≤2000001\le m\le 200000; 1≤u,v,a,b≤n1\le u,v,a,b\le n; 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 11 and 33 occur in all three paths. Each of vertices 2,4,52,4,5 occurs in exactly one path.