QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 256 MB Total points: 100

#331. 发射器

Statistics

Byteasar 成了 Bytown 附近一座历史悠久的盐矿的新负责人。为了增加其对游客的吸引力,他决定在矿井的走廊里安装无线网络。

该矿井由 $n$ 个房间和连接它们的 $n-1$ 条走廊组成。通过这些走廊,可以从任意一个房间到达其他任何房间。Byteasar 希望在房间内安装无线发射器,使得矿井中的每一条走廊都能覆盖到无线信号。连接房间 $a$ 和 $b$ 的走廊信号强度足够,当且仅当满足以下至少一个条件:

  • 房间 $a$ 或房间 $b$ 中装有发射器,或者
  • 在从房间 $a$ 或 $b$ 出发,经过至多一条走廊即可到达的房间集合中,总共至少装有两个发射器。

Byteasar 想知道,为了使所有走廊的信号强度都足够,最少需要安装多少个无线发射器。每个房间可以安装任意数量的发射器。

输入格式

输入的第一行包含一个正整数 $n$,表示矿井中房间的数量。这些房间编号为 $1$ 到 $n$。

接下来的 $n-1$ 行描述了矿井的走廊。每行包含两个整数 $a$ 和 $b$ ($1 \le a, b \le n, a \neq b$),由一个空格分隔,表示房间 $a$ 和 $b$ 之间直接由一条走廊相连。

输出格式

输出的第一行也是唯一一行应包含一个整数:Byteasar 需要部署的发射器的最小数量。

样例

样例输入 1

7
1 2
2 3
2 4
4 5
5 6
6 7

样例输出 1

2

样例输入 2

7
1 2
2 3
4 3
5 4
6 3
7 6

样例输出 2

2

说明

在第一个样例中,在 2 号和 6 号房间各安装一个发射器就足够了;而在第二个样例中,在 3 号房间安装两个发射器就足够了。

子任务

测试集由以下子任务组成。每个子任务内可能包含多个测试组。

子任务 属性 分值
1 $n \le 10$ 15
2 $n \le 500$ 20
3 $n \le 200\,000$,每个房间连接的走廊不超过三条 25
4 $n \le 200\,000$ 40

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.