Problem K. Strong connectivity

Author:StdAlg   Time limit:1 sec
Input file:input.txt   Memory limit:8 Mb
Output file:output.txt  

Statement

You are to write a program that receives a directed unweighted graph and finds all vertices of its strong-connected component, containing given vertex S.

Input file format

Input file contains two integers N, M and S. Vertices are numbered with integer numbers from 1 to N. M is the number of arcs. Each of next M lines contain pair of integers — starting and ending vertices of some arc respectively. There is at most one arc connecting two vertices in every direction.

Output file format

Output file must contain integer number T — amount of vertices in strong-connected component. After that, there must be T integer numbers in ascending order — vertices of compontent themselves.

Constraints

0 ≤ N, M ≤ 100000.

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
5 4 1
1 2
2 3
3 1
4 1
3 1 2 3

0.046s 0.008s 13