eolymp
bolt
Try our new interface for solving problems
Problems

Redundant Edges

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 C0). 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 C0.

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 (1n100000, 1m200000, 1rn): 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 ai and bi (1ai, bin) which introduce a directed edge from node ai to node bi. 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.

Time limit 1 second
Memory limit 128 MiB
Input example #1
3 3 1
1 2
2 3
3 1
Output example #1
1
3
Input example #2
4 6 2
2 1
2 3
3 1
3 4
1 4
4 2
Output example #2
5
1 3 4 5 6
Source 2013 Petrozavodsk, Moscow SU ST + NNSU Contest, Day 2, August 24, Problem J