아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Labyrinth

시간 제한3초메모리 제한512 MB

요약
방향 그래프에서 시작 정점 s와 도착 정점 t만 공유하는 두 개의 단순 경로를 찾거나, 그러한 경로가 없음을 판별한다.
난이도

보통10점 중 6점

유형
그래프, DFS, BFS
정답자
아직 제출이 없습니다

문제

Leslie and Leon entered a labyrinth. The labyrinth consists of nn halls and mm one-way passages between them. The halls are numbered from 11 to nn.

Leslie and Leon start their journey in the hall ss. Right away, they quarrel and decide to explore the labyrinth separately. However, they want to meet again at the end of their journey.

To help Leslie and Leon, your task is to find two different paths from the given hall ss to some other hall tt, such that these two paths do not share halls other than the staring hall ss and the ending hall tt. The hall tt has not been determined yet, so you can choose any of the labyrinth's halls as tt except ss.

Leslie's and Leon's paths do not have to be the shortest ones, but their paths must be simple, visiting any hall at most once. Also, they cannot visit any common halls except ss and tt during their journey, even at different times.

입력

The first line contains three integers nn, mm, and ss, where nn (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5) is the number of vertices, mm (0≤m≤2⋅1050 \le m \le 2 \cdot 10^5) is the number of edges in the labyrinth, and ss (1≤s≤n1 \le s \le n) is the starting hall.

Then mm lines with descriptions of passages follow. Each description contains two integers u_iu\_i, v_iv\_i (1≤u_i,v_i≤n1 \le u\_i, v\_i \le n; u_i≠v_iu\_i \neq v\_i), denoting a passage from the hall u_iu\_i to the hall v_iv\_i. The passages are one-way. Each tuple (u_i,v_i)(u\_i, v\_i) is present in the input at most once. The labyrinth can contain cycles and is not necessarily connected in any way.

출력

If it is possible to find the desired two paths, output "Possible", otherwise output "Impossible".

If the answer exists, output two path descriptions. Each description occupies two lines. The first line of the description contains an integer hh (2≤h≤n2 \le h \le n) --- the number of halls in a path, and the second line contains distinct integers w_1,w_2,…,w_hw\_1, w\_2, \dots, w\_h (w_1=sw\_1 = s; 1≤w_j≤n1 \le w\_j \le n; w_h=tw\_h = t) --- the halls in the path in the order of passing. Both paths must end at the same vertex tt. The paths must be different, and all intermediate halls in these paths must be distinct.

예제3

  1. 예제 1

    입력
    5 5 1
    1 2
    2 3
    1 4
    4 3
    3 5
    
    예상 출력
    Possible
    3
    1 2 3
    3
    1 4 3
    
  2. 예제 2

    입력
    5 5 1
    1 2
    2 3
    3 4
    2 5
    5 4
    
    예상 출력
    Impossible
    
  3. 예제 3

    입력
    3 3 2
    1 2
    2 3
    3 1
    
    예상 출력
    Impossible