QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#18585. ディミゴ統制

统计

2039年、Dimigoには1番から$N$番までの番号が付けられた$N$個の建物と、それらの建物を結ぶ$M$本の道がある。2つの建物を直接結ぶ道は1本以下である。

ある日、学校でウイルスが流行し、全校生徒が感染の危機に瀕した。これに対し、あなたはウイルスの拡散を防ぐため、以下の制御作業を0回以上行い、すべての道を制御することにした。

  • まだ制御されていない道と直接つながっている建物を1つ選択し、その建物と直接つながっているすべての道を制御する。

生徒の安全のため、あなたは制御作業を可能な限り多く行うことにした。このとき、制御作業をどのような順序で行うべきか求めよ。

入力

1行目に建物の数 $N$、道の数 $M$が空白区切りで与えられる。$(1 \le N \le 10^{5}; 0 \le M \le 10^{5})$

2行目から$M$行にわたり、各行に道が結ぶ2つの建物の番号 $u, v$が空白区切りで与えられる。$(1 \le u, v \le N; u \ne v)$

出力

1行目に制御作業を行える最大回数 $K$を出力する。

2行目から$K$行にわたり、各行に制御作業を行う建物の番号を順に1行ずつ出力する。

制御作業の回数を最大化する方法が複数ある場合は、そのうちのいずれか1つを出力すればよい。

入出力例

入力 1

3 3
3 2
3 1
2 1

出力 1

2
2
3

入力 2

10 8
4 10
10 7
1 4
8 6
10 1
1 9
7 4
9 5

出力 2

6
7
10
4
5
9
8

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.