Labyrinth
시간 제한3초메모리 제한512 MB
방향 그래프에서 시작 정점 s와 도착 정점 t만 공유하는 두 개의 단순 경로를 찾거나, 그러한 경로가 없음을 판별한다.
문제
Leslie and Leon entered a labyrinth. The labyrinth consists of halls and one-way passages between them. The halls are numbered from to .
Leslie and Leon start their journey in the hall . 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 to some other hall , such that these two paths do not share halls other than the staring hall and the ending hall . The hall has not been determined yet, so you can choose any of the labyrinth's halls as except .
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 and during their journey, even at different times.
입력
The first line contains three integers , , and , where () is the number of vertices, () is the number of edges in the labyrinth, and () is the starting hall.
Then lines with descriptions of passages follow. Each description contains two integers , (; ), denoting a passage from the hall to the hall . The passages are one-way. Each tuple 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 () --- the number of halls in a path, and the second line contains distinct integers (; ; ) --- the halls in the path in the order of passing. Both paths must end at the same vertex . The paths must be different, and all intermediate halls in these paths must be distinct.