QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 128 MB Points totaux : 100

#13322. 塔防游戏

Statistiques

Bytie 正在玩一款名为“塔防”的电脑游戏。他的目标是建造防御塔,以保护他的整个领地。Bytie 的领地中有多个城镇,其中一些城镇由双向道路连接。如果 Bytie 在一个城镇中建造了一座防御塔,那么该塔将保护该城镇及其所有直接通过道路相连的城镇。

正当 Bytie 思考如何在领地中布置防御塔时,他的姐姐 Bytea 走了进来。她看了一眼屏幕上的地图,片刻后惊呼道:“哎呀,这有什么好想的,显然 $k$ 座塔就足够了!”

Bytie 对姐姐破坏了他的乐趣感到愤怒,于是把她赶了出去,并开始思考下一步该怎么做。自尊心不允许他建造超过 $k$ 座塔。但他还有一张底牌:他可以研究一种技术,使他能够建造改进型防御塔。一座改进型防御塔不仅能保护它所在的城镇及其直接相邻的城镇,还能保护更远处的城镇。形式化地,在城镇 $u$ 建造的改进型防御塔保护城镇 $v$,当且仅当满足以下条件之一:

  • $u=v$;
  • 存在从 $u$ 到 $v$ 的直接道路;
  • 或者存在一个城镇 $w$,使得存在从 $u$ 到 $w$ 的直接道路,且存在从 $w$ 到 $v$ 的直接道路。

当然,Bytie 仍然致力于建造不超过 $k$ 座塔,但他完全不介意将这些塔换成改进型防御塔。

输入格式

标准输入的第一行包含三个整数 $n$、$m$ 和 $k$ ($2 \le n \le 500\,000$, $0 \le m \le 1\,000\,000$, $1 \le k \le n$),分别表示 Bytie 领地中的城镇数量、道路数量以及 Bytea 给出的数字 $k$,各数之间用空格分隔。

Bytie 领地中的城镇编号为 $1$ 到 $n$。接下来的 $m$ 行描述了道路。每一行包含两个整数 $a_{i}$ 和 $b_{i}$ ($1 \le a_{i}, b_{i} \le n$, $a_i \ne b_i$),表示城镇 $a_{i}$ 和 $b_{i}$ 之间有直接的双向道路相连。每对城镇之间最多只有一条道路。

输出格式

你的程序需要向标准输出打印两行,描述改进型防御塔在 Bytie 领地中的布置。第一行应包含一个整数 $r$ ($1 \le r \le k$),表示 Bytie 应该建造的改进型防御塔的数量。第二行应通过提供 $r$ 个互不相同的整数来指定这些塔的布置位置,这些整数即为建造改进型防御塔的城镇编号。城镇编号可以以任意顺序给出。

如果存在多种解,输出任意一种即可。请记住,任何不超过 $k$ 座改进型防御塔的布置方案都是可行的——你不需要最小化它们的数量。你可以假设 Bytea 是正确的,即 Bytie 的整个领地确实可以通过 $k$ 座普通(非改进型)防御塔来保护。因此,解总是存在的。

样例

样例输入 1

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

样例输出 1

3
1 5 7

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.