QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 256 MB Points totaux : 100 Hackable ✓

#14915. 冗余边

Statistiques

考虑一个由 $N$ 个节点和 $M$ 条有向边组成的有向图 $G$。节点从 $1$ 到 $N$ 编号,边从 $1$ 到 $M$ 编号。我们选择某个节点 $R$ 作为起点,并找出所有从 $R$ 出发沿着边移动可以到达的节点(将该集合记为 $C_0$)。定义 $C(e)$ 为在不使用编号为 $e$ 的边的情况下,从 $R$ 出发可以到达的节点集合。如果 $C(e)$ 等于 $C_0$,则称边 $e$ 是冗余的(redundant)。

给你图 $G$ 和起点 $R$。你的目标是找出所有的冗余边。

输入格式

输入的第一行包含三个整数 $N$、$M$ 和 $R$($1 \le N \le 100\,000$,$1 \le M \le 200\,000$,$1 \le R \le N$),分别表示节点数、边数和起点。

接下来的 $M$ 行描述图的边:其中第 $i$ 行包含两个整数 $a_i$ 和 $b_i$($1 \le a_i, b_i \le N$),表示一条从节点 $a_i$ 到节点 $b_i$ 的有向边。保证图中无自环,且对于任意两个节点 $u$ 和 $v$,从 $u$ 到 $v$ 最多只有一条有向边。

输出格式

第一行输出冗余边的数量。

第二行以任意顺序输出所有冗余边的编号。边按照输入中出现的顺序从 $1$ 开始编号。

样例

输入样例 1

3 3 1
1 2
2 3
3 1

输出样例 1

1
3

输入样例 2

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

输出样例 2

5
1 3 4 5 6

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.