QOJ.ac

QOJ

时间限制: 1 s 内存限制: 256 MB 总分: 100

#10500. 两条路径

统计

在 Bajtocja,城市之间由单向道路连接。那里的道路网络非常特殊:对于任何城市,如果我们沿着某条道路离开它,就无法再沿着道路的方向回到该城市。换句话说,我们可以将 Bajtocja 的道路网络想象成一个有向无环图。

Bajtocja 道路网络的特殊性带来了一些问题。有些城市甚至无法从首都到达。问题更严重的是,由于现代化改造,某些道路上的交通经常中断。居住在首都的 Bajtazar 经常前往 Bajtocja 的各个城市。他想知道对于每一个城市,是否能从首都通过两条不包含任何公共道路的路径到达。如果是这样,或者目标城市就是首都,那么 Bajtazar 就知道他前往该城市的旅程将是无忧的,即使其中一条路径上的某条(或多条)道路正在维修。

请帮助 Bajtazar 确定他可以无忧前往的城市集合。

输入格式

输入的第一行包含两个自然数 $n$ 和 $m$ ($1 \le n \le 200\,000, 1 \le m \le 500\,000$),分别表示城市数量和道路数量。城市编号从 $1$ 到 $n$。Bajtocja 的首都编号为 $1$。

接下来的 $m$ 行描述了道路。其中第 $i$ 行包含两个整数 $u_i$ 和 $v_i$ ($1 \le u_i, v_i \le n, u_i \neq v_i$),表示第 $i$ 条单向道路从城市 $u_i$ 通往城市 $v_i$。

输出格式

第一行输出 Bajtazar 可以无忧前往的城市数量。第二行按升序输出这些城市的编号,中间用空格分隔。

样例

输入 1

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

输出 1

4
1 4 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.