Redundant Edges
Consider a directed graph G consisting of n nodes and m directed edges. Nodes are numbered from 1 to n and edges are numbered from 1 to m. Let's select some node r as the starting one and find all nodes that are reachable from r by moving along edges (denote this set as C[0]
). Define C(e) as the set of nodes which are reachable from r using any edges except the one with number e. Edge e is called redundant if C(e) is equal to C[0]
.
You are given the graph G and the starting node r. Your goal is to find all redundant edges.
Input
The first line contains three integers n, m and r (1 ≤ n ≤ 100000, 1 ≤ m ≤ 200000, 1 ≤ r ≤ n): the number of nodes, the number of edges and the starting node, respectively. Next m lines describe the edges of the graph: i-th of them contains two integers a[i]
and b[i]
(1 ≤ a[i]
, b[i]
≤ n) which introduce a directed edge from node a[i]
to node b[i]
. It is guaranteed that there are no loops, and for any two nodes u and v, there is at most one edge from u to v.
Output
On the first line, print the number of redundant edges. On the second line, print the numbers of all redundant edges in any order. Edges are numbered starting from 1 according to their order in the input.