Codeforces Round 121 (Div. 1)
C
Fools and Roads
Codeforces
1900
原题
← BD →
翻译中…

They say that Berland has exactly two problems, fools and roads. Besides, Berland has $*n*$ cities, populated by the fools and connected by the roads. All Berland roads are bidirectional. As there are many fools in Berland, between each pair of cities there is a path (or else the fools would get upset). Also, between each pair of cities there is no more than one simple path (or else the fools would get lost).

翻译中…

But that is not the end of Berland's special features. In this country fools sometimes visit each other and thus spoil the roads. The fools aren't very smart, so they always use only the simple paths.

翻译中…

A simple path is the path which goes through every Berland city not more than once.

翻译中…

The Berland government knows the paths which the fools use. Help the government count for each road, how many distinct fools can go on it.

翻译中…

Note how the fools' paths are given in the input.

翻译中…

Input

翻译中…

The first line contains a single integer $*n*$ ($2 ≤ *n* ≤ 10^{5}$) — the number of cities.

翻译中…

Each of the next $*n* - 1$ lines contains two space-separated integers $*u*_{*i*}, *v*_{*i*}$ ($1 ≤ *u*_{*i*}, *v*_{*i*} ≤ *n*$, $*u*_{*i*} ≠ *v*_{*i*}$), that means that there is a road connecting cities $*u*_{*i*}$ and $*v*_{*i*}$.

翻译中…

The next line contains integer $*k*$ ($0 ≤ *k* ≤ 10^{5}$) — the number of pairs of fools who visit each other.

翻译中…

Next $*k*$ lines contain two space-separated numbers. The $*i*$-th line $(*i* > 0)$ contains numbers $*a*_{*i*}, *b*_{*i*}$ ($1 ≤ *a*_{*i*}, *b*_{*i*} ≤ *n*$). That means that the fool number $2*i* - 1$ lives in city $*a*_{*i*}$ and visits the fool number $2*i*$, who lives in city $*b*_{*i*}$. The given pairs describe simple paths, because between every pair of cities there is only one simple path.

翻译中…

Output

翻译中…

Print $*n* - 1$ integer. The integers should be separated by spaces. The $*i*$-th number should equal the number of fools who can go on the $*i*$-th road. The roads are numbered starting from one in the order, in which they occur in the input.

翻译中…

Note

翻译中…

In the first sample the fool number one goes on the first and third road and the fool number 3 goes on the second, first and fourth ones.

翻译中…

In the second sample, the fools number 1, 3 and 5 go on the first road, the fool number 5 will go on the second road, on the third road goes the fool number 3, and on the fourth one goes fool number 1.

翻译中…

样例

Input #1
5
1 2
1 3
2 4
2 5
2
1 4
3 5
Output #1
2 1 1 1
InputCopy OutputCopy
Input #2
5
3 4
4 5
1 4
2 4
3
2 3
1 3
3 5
Output #2
3 1 1 1
InputCopy OutputCopy
题目信息
题号
191C
时间限制
2 s
内存限制
256 MB
标签
数据结构
DFS 及类似
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。