#P12825. [NERC 2021] Labyrinth

    ID: 12605 Type: RemoteJudge 3000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 3 Uploaded By: Tags>2021Special JudgeICPCNERC/NEERC

[NERC 2021] Labyrinth

题目描述

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 (2n21052 \le n \le 2 \cdot 10^5) is the number of vertices, mm (0m21050 \le m \le 2 \cdot 10^5) is the number of edges in the labyrinth, and ss (1sn1 \le s \le n) is the starting hall.

Then mm lines with descriptions of passages follow. Each description contains two integers uiu_i, viv_i (1ui,vin1 \le u_i, v_i \le n; uiviu_i \neq v_i), denoting a passage from the hall uiu_i to the hall viv_i. The passages are one-way. Each tuple (ui,vi)(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\tt{Possible}, otherwise output Impossible\tt{Impossible}.

If the answer exists, output two path descriptions. Each description occupies two lines. The first line of the description contains an integer hh (2hn2 \le h \le n) --- the number of halls in a path, and the second line contains distinct integers w1,w2,,whw_1, w_2, \dots, w_h (w1=sw_1 = s; 1wjn1 \le w_j \le n; wh=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.

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