A10000 | Zublicanes and Mumocrates
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
It's election time in Berland. The favorites are of course parties of zublicanes and mumocrates. The election campaigns of both parties include numerous demonstrations on $n$ main squares of the capital of Berland. Each of the $n$ squares certainly can have demonstrations of only one party, otherwise it could lead to riots. On the other hand, both parties have applied to host a huge number of demonstrations, so that on all squares demonstrations must be held. Now the capital management will distribute the area between the two parties.
Some pairs of squares are connected by $(n-1)$ bidirectional roads such that between any pair of squares there is a unique way to get from one square to another. Some squares are on the outskirts of the capital meaning that they are connected by a road with only one other square, such squares are called dead end squares.
The mayor of the capital instructed to distribute all the squares between the parties so that the dead end squares had the same number of demonstrations of the first and the second party. It is guaranteed that the number of dead end squares of the city is even.
To prevent possible conflicts between the zublicanes and the mumocrates it was decided to minimize the number of roads connecting the squares with the distinct parties. You, as a developer of the department of distributing squares, should determine this smallest number.
Some pairs of squares are connected by $(n-1)$ bidirectional roads such that between any pair of squares there is a unique way to get from one square to another. Some squares are on the outskirts of the capital meaning that they are connected by a road with only one other square, such squares are called dead end squares.
The mayor of the capital instructed to distribute all the squares between the parties so that the dead end squares had the same number of demonstrations of the first and the second party. It is guaranteed that the number of dead end squares of the city is even.
To prevent possible conflicts between the zublicanes and the mumocrates it was decided to minimize the number of roads connecting the squares with the distinct parties. You, as a developer of the department of distributing squares, should determine this smallest number.
输入格式
The first line of the input contains a single integer $n$ ( $2<=n<=5000$ ) — the number of squares in the capital of Berland.
Next $n-1$ lines contain the pairs of integers $x,y$ ( $1<=x,y<=n,x≠y$ ) — the numbers of the squares connected by the road. All squares are numbered with integers from $1$ to $n$ . It is guaranteed that the number of dead end squares of the city is even.
Next $n-1$ lines contain the pairs of integers $x,y$ ( $1<=x,y<=n,x≠y$ ) — the numbers of the squares connected by the road. All squares are numbered with integers from $1$ to $n$ . It is guaranteed that the number of dead end squares of the city is even.
输出格式
Print a single number — the minimum number of roads connecting the squares with demonstrations of different parties.
输入输出样例
输入 #1
8 1 4 2 4 3 4 6 5 7 5 8 5 4 5
输出 #1
1
输入 #2
5 1 2 1 3 1 4 1 5
输出 #2
2
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted