QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#2514. 电缆保护

الإحصائيات

ICPC(国际电缆保护公司)生产一种电缆保护工具,可以安装在网络交换机中,以监控与其相连的所有电缆链路是否正常工作。由于保护工具会导致传输延迟,因此不适合在每台交换机上都进行安装。

通常,网络拓扑由两部分组成:骨干网和若干子网。骨干网上的交换机以环形结构连接,每个骨干交换机被视为一个子网的根,子网中的交换机以树状结构连接。我们将这种拓扑称为单环拓扑(unicyclic topology)。图 2 展示了一个单环拓扑的示例。

图 2:单环拓扑示例。

假设有 $n$ 台骨干交换机和 $m$ 台子网交换机。交换机编号为 $0$ 到 $n + m - 1$ 的整数。骨干交换机按顺时针顺序编号为 $0$ 到 $n - 1$,子网交换机编号为 $n$ 到 $n + m - 1$,其中每个子网交换机的编号都大于其在所属子网树状结构中的父节点编号。图 3 展示了一个交换机编号的示例。

图 3:交换机编号示例。

请为 ICPC 编写一个程序,以确定为监控所有电缆链路而选择安装电缆保护工具的交换机的最小数量。图 4 展示了给定网络的一个最优解(用椭圆圈出)。

图 4:给定网络的一个最优解。

输入格式

输入文件的第一行包含两个整数 $n$ 和 $m$,用空格分隔,分别表示骨干交换机和子网交换机的数量。接下来的 $n + m$ 行,每行包含两个整数,用空格分隔,表示一条链路的两个端点交换机的编号。

输出格式

输出为监控所有电缆链路而选择安装电缆保护工具的交换机的最小数量。

数据范围

  • $3 \le n \le 100000$
  • $1 \le m \le 100000$

样例

样例输入 1

3 2
0 1
1 2
0 2
1 3
2 4

样例输出 1

2

样例输入 2

4 11
0 1
0 3
0 4
0 5
1 2
1 6
2 3
2 9
3 12
6 7
6 8
9 10
10 11
12 13
12 14

样例输出 2

5

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.