A11749 | Maximum Control (easy)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The Resistance is trying to take control over all planets in a particular solar system. This solar system is shaped like a tree. More precisely, some planets are connected by bidirectional hyperspace tunnels in such a way that there is a path between every pair of the planets, but removing any tunnel would disconnect some of them.
The Resistance already has measures in place that will, when the time is right, enable them to control every planet that is not remote. A planet is considered to be remote if it is connected to the rest of the planets only via a single hyperspace tunnel.
How much work is there left to be done: that is, how many remote planets are there?
The Resistance already has measures in place that will, when the time is right, enable them to control every planet that is not remote. A planet is considered to be remote if it is connected to the rest of the planets only via a single hyperspace tunnel.
How much work is there left to be done: that is, how many remote planets are there?
输入格式
The first line of the input contains an integer $N$ ( $2<=N<=1000$ ) – the number of planets in the galaxy.
The next $N-1$ lines describe the hyperspace tunnels between the planets. Each of the $N-1$ lines contains two space-separated integers $u$ and $v$ ( $1<=u,v<=N$ ) indicating that there is a bidirectional hyperspace tunnel between the planets $u$ and $v$ . It is guaranteed that every two planets are connected by a path of tunnels, and that each tunnel connects a different pair of planets.
The next $N-1$ lines describe the hyperspace tunnels between the planets. Each of the $N-1$ lines contains two space-separated integers $u$ and $v$ ( $1<=u,v<=N$ ) indicating that there is a bidirectional hyperspace tunnel between the planets $u$ and $v$ . It is guaranteed that every two planets are connected by a path of tunnels, and that each tunnel connects a different pair of planets.
输出格式
A single integer denoting the number of remote planets.
输入输出样例
输入 #1
5 4 1 4 2 1 3 1 5
输出 #1
3
输入 #2
4 1 2 4 3 1 4
输出 #2
2
In the first example, only planets $2$ , $3$ and $5$ are connected by a single tunnel.
In the second example, the remote planets are $2$ and $3$ .
Note that this problem has only two versions – easy and medium.
In the second example, the remote planets are $2$ and $3$ .
Note that this problem has only two versions – easy and medium.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted