#CF191C. 傻瓜与道路(Fools and Roads)

0

傻瓜与道路(Fools and Roads)

傻瓜与道路(Fools and Roads)

题目描述

有一颗 nn 个节点的树,kk 次旅行,问每一条边被走过的次数。

输入格式

第一行一个整数 nn (2≤n≤1052\leq n\leq 10^5 )。

接下来 n−1n-1 行,每行两个正整数 x,yx,y (1≤x,y≤n,x≠y1\leq x,y\leq n,x\neq y ),表示 xx 与 yy 之间有一条连边。

接下来一个整数 kk (0≤k≤1050\leq k\leq 10^5 )。

接下来 kk 行,每行两个正整数 x,yx,y (1≤x,y≤n1\leq x,y\leq n ),表示有一个从 xx 到 yy 的旅行。

输出格式

一行空格分隔的 n−1n - 1 个整数,按输入顺序输出每一条边被走过的次数。

Translated by @larryzhong

样例输入 #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 33 goes on the second, first and fourth ones.

In the second sample, the fools number 11, 33 and 55 go on the first road, the fool number 55 will go on the second road, on the third road goes the fool number 33, and on the fourth one goes fool number 11.

知识点与难度

本题涉及的知识点从属于 CSP-S,难度(CF Rating):1600。


测试点分布

Subtask 分值 测试点编号 说明
0 10 1~2 样例
1 25 3~8 小规模与边界测试数据
2 30 9~16 中等规模测试数据
3 35 17~25 满规模极限测试数据

出处:原题链接