CF191C.Fools and Roads

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

They say that Berland has exactly two problems, fools and roads. Besides, Berland has nn 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.

输入格式

The first line contains a single integer nn ( 2<=n<=1052<=n<=10^{5} ) — the number of cities.

Each of the next n1n-1 lines contains two space-separated integers ui,viu_{i},v_{i} ( 1<=ui,vi<=n1<=u_{i},v_{i}<=n , uiviu_{i}≠v_{i} ), that means that there is a road connecting cities uiu_{i} and viv_{i} .

The next line contains integer kk ( 0<=k<=1050<=k<=10^{5} ) — the number of pairs of fools who visit each other.

Next kk lines contain two space-separated numbers. The ii -th line (i>0)(i>0) contains numbers ai,bia_{i},b_{i} ( 1<=ai,bi<=n1<=a_{i},b_{i}<=n ). That means that the fool number 2i12i-1 lives in city aia_{i} and visits the fool number 2i2i , who lives in city bib_{i} . The given pairs describe simple paths, because between every pair of cities there is only one simple path.

输出格式

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

输入输出样例

  • 输入#1

    5
    1 2
    1 3
    2 4
    2 5
    2
    1 4
    3 5
    

    输出#1

    2 1 1 1 
    
  • 输入#2

    5
    3 4
    4 5
    1 4
    2 4
    3
    2 3
    1 3
    3 5
    

    输出#2

    3 1 1 1 
    

说明/提示

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.

首页