13390 - Domo the Builder   

Description

Domo is a builder, he wants to build some one-way bridges to travel around islands.

 

Given a series of one-way bridges and the island where Domo is in the beginning, please find which island(s) Domo can reach.

 

 

 

For example, the sample gives 5 islands and 5 one-way bridges shown as below:

It's easy to find that we can reach islands with indices 1, 2, and 3.

 

Input

The first line consists of three integers N, K, and S (1 ≤ N ≤ 1000, 1 ≤ K ≤ N⋅(N-1), 1 ≤ S ≤ N) denoting that the number of islands, the number of one-way bridges, and the island where Domo is in the beginning.

 

In the following K lines, each line consists of two integers A, B (1 ≤ A, B ≤ N) denoting that there's a one-way bridge from A to B.

 

Output

The output only consists of one line, indicating the islands that Domo can reach.

 

Notice that if there are multiple islands that Domo can reach, print them in increasing order and separate them by whitespace.

 

Sample Input  Download

Sample Output  Download

Tags




Discuss