#P12825. [NERC 2021] Labyrinth
[NERC 2021] Labyrinth
题目描述
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 , otherwise output .
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.
5 5 1
1 2
2 3
1 4
4 3
3 5
Possible
3
1 2 3
3
1 4 3
5 5 1
1 2
2 3
3 4
2 5
5 4
Impossible
3 3 2
1 2
2 3
3 1
Impossible