#P8124. [BalticOI 2021] From Hacks to Snitches (Day1)
[BalticOI 2021] From Hacks to Snitches (Day1)
Description
You are given an undirected graph with vertices and edges. There are guards. Guard passes through vertices, which are . The movement rule is as follows: the guard starts at vertex at minute . At minute , it moves from to ; at minute , it moves from to ; ; at minute , it moves from to ; at minute , it moves from back to . Then it repeats this cycle forever.
You are a thief. You want to go from vertex to vertex . That is, at minute you are at vertex . You may move directly from one vertex to another, but you must traverse a path between these two vertices. You must ensure that there is no guard on any vertex along this path, and also that no guard traverses any edge that belongs to this path. Traversing each edge takes you exactly one minute. It is guaranteed that the routes of any two guards are vertex-disjoint, and that both the start and the end vertices are not on any guard route.
You need to find the minimum number of minutes to reach vertex without being detected by the guards, or report that it is impossible.
Input Format
The first line contains two integers , the number of vertices and edges.
The next lines each contain two integers , describing an edge.
Line contains an integer , the number of guards.
The next lines each start with an integer , the length of the guard's route, followed by integers describing the route.
Output Format
Output one line containing one integer, the minimum number of minutes required, or output impossible if there is no solution.
6 6
1 2
2 3
3 4
4 5
5 2
5 6
1
4 3 2 5 4
4
6 6
1 2
2 3
3 4
4 5
5 2
5 6
1
4 4 5 2 3
5
11 13
1 2
2 3
3 4
4 2
3 5
5 6
6 7
7 5
6 8
8 9
9 10
10 8
9 11
3
3 4 2 3
3 7 6 5
3 10 8 9
impossible
Hint
Sample 1 Explanation
The route of guard is as follows:

One feasible way is:
- At minute , start at vertex .
- At minute , wait at vertex .
- At minute , move to vertex .
- At minute , move to vertex .
- At minute , move to vertex .
Sample 2 Explanation
The graph and routes are the same as in sample 1, but the start and end vertices are different.
One feasible way is: do not wait, and go directly along .
Constraints
This problem uses bundled testdata.
- Subtask 1 (5 pts): , , .
- Subtask 2 (10 pts): , , and satisfies Property A.
- Subtask 3 (10 pts): , , and satisfies Property A.
- Subtask 4 (10 pts): satisfies Property A.
- Subtask 5 (25 pts): .
- Subtask 6 (20 pts): , .
- Subtask 7 (20 pts): no special restrictions.
- Subtask Ex (0 pts): Extra Subtask.
For of the testdata, , , , .
Property A means that there is no edge connecting any two guard routes.
Notes
Translated from BalticOI 2021 Day1 C From Hacks to Snitches。
Translated by ChatGPT 5
京公网安备 11011102002149号