#P3443. [POI 2006] LIS-The Postman
[POI 2006] LIS-The Postman
Description
Every morning, a busy postman needs to traverse all the city’s streets to deliver mail. All roads in the city are one-way and connected by intersections. For any two intersections , there are at most two streets directly between them: one and one (i.e., there are no two streets). All intersections are numbered from to .
At intersection , the postman may start his trip or end his trip. For a long time, the postman could freely choose his route, but a new regulation has disrupted his plan: each postman has been given several sequences of intersections, and now his route must satisfy the following requirements:
- The route must start at intersection and end at intersection .
- The route must traverse each street exactly once.
- Each prescribed sequence of intersections must appear contiguously in the route. For example: the sequence
1 2 1appears in1 2 1 3, but does not appear in1 2 3 1(not contiguous).
The postman asks you to determine whether there exists a route that satisfies the above conditions; if so, also provide one such route.
Input Format
The first line contains two integers , the number of intersections and the number of streets.
The next lines each contain two integers , indicating there is a street . It is guaranteed that identical streets are not repeated and there are no self-loops.
The next line contains an integer , the number of prescribed intersection sequences.
The next lines each describe one prescribed sequence: the first integer is , followed by integers giving the sequence.
Output Format
If there exists a route that satisfies the conditions, output TAK; otherwise, output NIE.
If the answer is TAK, then output the route in the following lines, one integer per line.
Suppose you output integers, where the -th printed integer is . Your output must satisfy the following conditions:
- .
- For all , there exists a street from to .
- Each street in the city is used exactly once.
- Each prescribed intersection sequence appears contiguously in the route.
6 10
1 5
1 3
4 1
6 4
3 6
3 4
4 3
5 6
6 2
2 1
4
3 1 5 6
3 3 4 3
4 4 3 6 4
3 5 6 2
TAK
1
3
4
3
6
4
1
5
6
2
1
Hint
Constraints: , , , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号