QOJ.ac

QOJ

実行時間制限: 3.0 s メモリ制限: 1024 MB 満点: 100

#11619. 孩子的噩梦

統計

Vasya 非常喜欢树,但非常讨厌图中的环。每当他在比赛中遇到仙人掌图问题时,他都会感到沮丧,并开始在社区中一个著名的论坛上发帖讨论。

今天,在训练营重要比赛的前一天晚上,Vasya 做了一个噩梦。在这个噩梦中,他看到了一个包含许多环的连通无向图:环中套环,环中又有环……这个图非常糟糕,以至于对于每一个至少包含四个顶点的简单环,图中都存在一条连接该环中两个不相邻顶点的边。

Vasya 唯一能做的就是删除一个顶点以及所有与该顶点关联的边。请帮助 Vasya 删除一些顶点,使得剩余顶点的数量尽可能多,且剩余的图中没有任何环。注意,删除顶点后,图可能会变得不连通。

输入格式

第一行包含两个整数 $n$ 和 $m$:图中顶点的数量和边的数量 ($1 \le n, m \le 200\,000$)。

接下来 $m$ 行,每行包含一对整数 $u$ 和 $v$:表示由边连接的两个顶点 ($1 \le u, v \le n$)。

保证图是连通的,没有自环,没有重边,并且对于每一个至少包含四个顶点的简单环,都存在一条连接该环中两个不相邻顶点的边。

输出格式

第一行输出一个整数 $t$:图中可以保留的顶点的最大数量。

第二行输出 $t$ 个整数:可以保留在图中的顶点编号。如果存在多种方案,输出其中任意一种即可。

样例

样例输入 1

3 2
1 2
2 3

样例输出 1

3
1 2 3

样例输入 2

3 3
1 2
2 3
3 1

样例输出 2

2
1 2

样例输入 3

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

样例输出 3

6
2 4 5 6 7 8

说明

在下图中,你可以看到样例 3 中的图。实线顶点和边是保留在结果图中的,虚线顶点和边是被删除的。

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.