luogu#P8391. [BalticOI 2022] Event Hopping (Day1)
[BalticOI 2022] Event Hopping (Day1)
Problem Description
There are intervals. The -th interval is .
You can hop between intervals. When you are at interval , you can hop to an interval that covers the right endpoint , i.e., you can hop from to if and only if .
There are queries. In each query, you start at interval and need to hop to interval . You need to output the minimum number of hops required. If it is impossible to reach it, output impossible.
Input Format
The first line contains two integers .
The next lines each contain two integers .
The next lines each contain two integers .
Output Format
Output lines. On the -th line, output the answer to the -th query. If there is no solution, output impossible.
5 2
1 3
2 4
4 7
7 9
3 7
1 4
3 2
2
impossible
8 5
1 2
3 4
1 5
6 7
5 10
10 20
15 20
999999999 1000000000
1 6
1 7
2 4
3 3
5 8
3
4
impossible
0
impossible
Hint
- Subtask ( points): Each interval can hop to at most one other interval.
- Subtask ( points): , .
- Subtask ( points): .
- Subtask ( points): .
- Subtask ( points): There do not exist two intervals such that .
- Subtask ( points): No special constraints.
For all testdata, , , .
Translated by ChatGPT 5