A8660 | Fools and Roads
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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 $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 $2i-1$ lives in city $a_{i}$ and visits the fool number $2i$ , who lives in city $b_{i}$ . The given pairs describe simple paths, because between every pair of cities there is only one simple path.
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 $2i-1$ lives in city $a_{i}$ and visits the fool number $2i$ , who lives in city $b_{i}$ . The given pairs describe simple paths, because between every pair of cities there is only one simple path.
输出格式
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.
输入输出样例
输入 #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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted