QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 256 MB 満点: 100

#12557. 国王的视察

統計

Karl 国王是一位负责且勤勉的统治者。每年他都会巡视全国,以确保所有城市都治理良好。

他的国家有 $n$ 个城市和 $m$ 条道路。为了管理旅行者,每条道路都是单向的,即从城市 $a$ 到城市 $b$ 的道路不能从 $b$ 反向通行到 $a$。

Karl 希望沿着这些道路进行一次旅行,使得他从首都出发,恰好访问每一个非首都城市一次,并最终回到首都。

作为交通部长,你有义务找到这样一条路线,或者确定这样的路线不存在。

输入格式

第一行包含两个整数 $n$ 和 $m$ ($2 \le n \le 100\,000$, $0 \le m \le n + 20$),分别表示城市数量和道路数量。

接下来的 $m$ 行,每行包含两个整数 $a_i$ 和 $b_i$ ($1 \le a_i, b_i \le n$),表示存在一条从城市 $a_i$ 到城市 $b_i$ 的单向道路。城市编号为 $1$ 到 $n$。首都编号为 $1$。

输出格式

如果存在一条从首都出发,恰好访问每个非首都城市一次,并回到首都的路线,则输出 $n + 1$ 个由空格分隔的整数,表示路线上的城市序列。请务必在路线的开头和结尾都输出首都。

如果不存在这样的路线,输出 “There is no route, Karl!”(不含引号)。

样例

样例输入 1

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

样例输出 1

1 3 4 2 1

样例输入 2

4 3
1 4
1 4
2 2

样例输出 2

There is no route, Karl!

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.