PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000073. Bãi đỗ xe (Parking)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Bãi đỗ xe (Parking)

Parking

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A parking lot has NN spaces and MM two-way roads. The entrance is connected to space SS. Initially all spaces are empty and every space is reachable from SS.

People 1,2,…,N1,2,\ldots,N arrive in order. Person ii will park only in space ii. They can do so if there is a path from the entrance to that space using only unoccupied spaces. If successful, space ii becomes occupied and cannot be traversed later; otherwise the person leaves. List all people who successfully park.

The entrance leads directly to parking space SS. To park at space ii, a driver must be able to reach it from the entrance using only currently vacant spaces. If space SS has already been occupied, later drivers cannot pass through it to reach any other space.

A driver who cannot park leaves without occupying any space. Only successful drivers change the parking lot's state. Print only the indices of those drivers, in increasing order.

Input

The first line contains N,M,SN,M,S. The next MM lines describe roads ui,viu_i,v_i.

Output

Print the indices of all successful people in increasing order, one per line.

Subtasks

  • Subtask 1 (20 points): 2≤N≤302\le N\le 30; 1≤M≤1201\le M\le 120; 1≤S≤N1\le S\le N; 1≤ui,vi≤N1\le u_i,v_i\le N, ui≠viu_i\ne v_i; the initial graph is connected.
  • Subtask 2 (30 points): 2≤N≤30002\le N\le 3000; 1≤M≤60001\le M\le 6000; 1≤S≤N1\le S\le N; 1≤ui,vi≤N1\le u_i,v_i\le N, ui≠viu_i\ne v_i; the initial graph is connected.
  • Subtask 3 (50 points): 2≤N≤2000002\le N\le 200000; 1≤M≤2000001\le M\le 200000; 1≤S≤N1\le S\le N; 1≤ui,vi≤N1\le u_i,v_i\le N, ui≠viu_i\ne v_i; the initial graph is connected.

Examples

Input

3 3 2
1 2
2 3
1 3

Output

1
2

Explanation

Driver 11 reaches space 11 through space 22 and parks. Driver 22 parks at space 22, directly beside the entrance. Since this space is now occupied, driver 33 cannot enter the lot to reach space 33, even though spaces 11 and 33 are connected. The successful drivers are 11 and 22.