QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 1024 MB 總分: 100

#6388. 网络

统计

Rui Yuan the Duck 正在构建一个新网络来运行他所有的应用程序。该网络由 $n$ 台服务器组成,编号为 $1$ 到 $n$。此外还有 $n - 1$ 条网络链路,编号为 $1$ 到 $n - 1$,用于连接这些服务器。

第 $i$ 条链路双向连接服务器 $u[i]$ 和 $v[i]$。保证仅使用这些服务器和网络链路,可以从任意一台服务器到达任何其他服务器。

最初,所有 $n$ 台服务器均处于活动状态。Rui Yuan 有 $m$ 个正在运行的应用程序,它们的 ID 分别为 $1$ 到 $m$。每个应用程序都有 $2$ 个数据库。应用程序 $j$ 的数据库位于服务器 $a[j]$ 和 $b[j]$(它们可能是同一台服务器)。两个不同的应用程序可能在同一台服务器上拥有数据库。

为了使应用程序 $j$ 正常工作,它的两个数据库必须通过网络链路和活动服务器连接起来。准确地说,当且仅当满足以下两个条件时,应用程序 $j$ 处于工作状态: 服务器 $a[j]$ 和 $b[j]$ 均处于活动状态。 仅使用网络链路和活动服务器,可以从服务器 $a[j]$ 到达服务器 $b[j]$。

Rui Yuan 请 Benson the Rabbit 来测试他的网络。利用他的黑客技能,Benson 可以选择任意一组服务器并同时停用它们。网络的鲁棒性是指为了确保所有 $m$ 个应用程序都不工作,所必须停用的最少服务器数量。

Benson 非常忙,他希望你帮他计算网络的鲁棒性,以及他应该停用的服务器选择,这样他就不会浪费时间停用多余的服务器。

输入格式

你的程序必须从标准输入读取数据。

第一行包含两个整数 $n$ 和 $m$。

接下来 $n - 1$ 行,第 $i$ 行包含两个整数 $u[i]$ 和 $v[i]$,表示第 $i$ 条网络链路连接的服务器。

接下来 $m$ 行,第 $j$ 行包含两个整数 $a[j]$ 和 $b[j]$,表示存储应用程序 $j$ 数据库的服务器。

输出格式

你的程序必须输出到标准输出。

输出两行。第一行包含一个整数,表示网络的鲁棒性,记为 $x$。

第二行包含 $x$ 个整数,表示应该停用的服务器。这 $x$ 个整数必须互不相同。你可以以任意顺序输出它们。

子任务

对于所有测试用例,输入满足以下范围: $1 \le n \le 200\,000$ $1 \le m \le 200\,000$ $1 \le u[i], v[i] \le n, u[i] \neq v[i]$(对于所有 $1 \le i \le n$)。 $1 \le a[j], b[j] \le n$(对于所有 $1 \le j \le m$) * 仅使用服务器和网络链路,可以从任意一台服务器到达任何其他服务器。

你的程序将在满足以下限制的输入实例上进行测试:

子任务 分值 附加限制
1 4 $a[i] = b[i]$
2 17 $u[i] = i, v[i] = i + 1$
3 14 $n, m \le 15$
4 29 $n, m \le 2000$
5 36 无附加限制

样例

样例输入 1

9 4
1 2
2 3
2 6
3 4
4 5
4 7
6 9
7 8
6 2
5 3
4 8
5 9

样例输出 1

2
4 2

说明 1

该输入描述的网络可以用下图表示:

假设服务器 $4$ 和 $2$ 被停用,则所有应用程序都将无法工作,如下所示: $b[1] = 2$,因此应用程序 $1$ 不工作。 从服务器 $a[2] = 5$ 到服务器 $b[2] = 3$ 的路径必须经过服务器 $4$,因此应用程序 $2$ 不工作。 $a[3] = 4$,因此应用程序 $3$ 不工作。 从服务器 $a[4] = 5$ 到服务器 $b[4] = 9$ 的路径必须经过服务器 $2$ 和 $4$,因此应用程序 $4$ 不工作。

可以证明,通过停用单个服务器无法确保所有应用程序都不工作。因此,网络的鲁棒性为 $2$。

注意,你可以以任意顺序输出所选服务器,因此以下输出也是有效的:

2
2 4

另请注意,可能存在其他导致所有应用程序不工作的 $2$ 台服务器的选择。

样例输入 2

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

样例输出 2

4
3 2 4 1

说明 2

注意,你可以以任意顺序输出所选服务器。例如,以下输出也是有效的:

4
4 3 2 1

样例输入 3

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

样例输出 3

2
4 6

样例输入 4

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

样例输出 4

2
2 1

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.