QOJ.ac

QOJ

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

#9340. Cheat

統計

Eryk 和他的搭档 “Synek” 正在策划下一次骗局。通常,他们通过以低汇率提供假钞来诈骗外国人,因此他们必须在全国各地频繁驾车往返以防被认出。

为了做到这一点,他们需要找到一个城市来建立基地。他们祖国的城市和道路可以被看作一个含有 $n$ 个顶点的有向图,顶点用 $1$ 到 $n$ 的整数编号,并且具有一个特殊的性质——对于每个合法的 $i$,都存在一条从顶点 $i$ 到顶点 $i + 1$ 的有向边。

由于他们希望在每次“旅行”后都能回到基地,因此他们觉得环非常吸引人。他们决定将基地建在位于国家中所有环上的城市。因为可能存在多个这样的城市,他们请求你将所有这些城市记录下来。如果图中不存在环,他们可以在任何城市建立基地。

形式上,一个环是一条起点和终点相同,且访问了至少一个其他城市(可能多次访问)的路径。

输入格式

第一行给出一个整数 $Z \le 50$,表示接下来描述的测试用例数量。

每个测试用例的第一行包含两个整数 $n$ 和 $m$,分别表示城市和道路的数量。

接下来的 $m$ 行中,每行包含两个整数 $a_i, b_i$($a_i \neq b_i$),表示存在一条从 $a_i$ 到 $b_i$ 的有向道路。从 $a_i$ 到 $b_i$ 可能存在多条道路。

$n \in [1, 500\,000]$,$m \in [0, 500\,000]$,所有测试用例中 $n$ 的总和以及 $m$ 的总和均不超过 $1\,000\,000$。

输出格式

对于每个测试用例,你的程序应该输出可以建立基地的城市数量,随后按升序输出这些城市的编号。

样例

输入样例 1

sample.in

输出样例 1

sample.out

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.