#P11801. 【MX-X9-T5】『GROI-R3』Star Trip
【MX-X9-T5】『GROI-R3』Star Trip
Problem Description
For an integer sequence , we call a prefix maximum if and only if there does not exist such that .
For an integer sequence , define its weight as the number of its prefix maxima.
Xiaoxun has a connected graph with vertices and undirected edges, where the vertices are numbered from to . It is guaranteed that the graph is connected, but it is not guaranteed to be a simple graph.
Yinli has queries. In each query, two vertices are given. You need to find a path that starts from vertex and ends at vertex (, , and there is an edge connecting and ), such that the weight of the sequence is minimized. You only need to output the minimum weight.
In particular, the path is not required to be a simple path. That is, it may pass through repeated edges or vertices.
Input Format
The first line contains three positive integers .
The next lines each contain two positive integers , representing an edge connecting vertices and .
The next lines each contain two positive integers , representing a query.
Output Format
Output lines, each containing one positive integer, denoting the answer to the corresponding query.
8 10 4
1 8
2 5
3 6
2 6
3 8
1 6
2 1
4 8
3 4
6 7
2 7
4 3
5 4
3 8
2
1
2
2
20 20 20
8 19
19 11
11 18
11 20
20 9
18 13
19 1
11 16
19 5
1 2
2 15
18 6
16 7
8 10
5 4
18 14
11 17
10 12
7 3
1 9
13 14
11 18
13 16
13 16
3 14
20 20
16 18
14 19
8 19
5 20
7 17
14 15
16 18
7 18
6 10
16 17
14 19
3 16
20 20
20 20
2
2
2
2
4
1
2
3
2
3
3
3
2
3
3
2
3
3
1
1
Hint
[Sample Explanation #1]
The sample graph is as follows:

- For the query , one path with minimum weight is , and its weight is .
- For the query , one path with minimum weight is , and its weight is .
- For the query , one path with minimum weight is , and its weight is .
- For the query , one path with minimum weight is , and its weight is .
[Constraints]
This problem uses bundled testdata.
| Subtask ID | Special Property | Score | ||
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | A | |||
| 6 | B | |||
| 7 | ||||
- Special Property A: It is guaranteed that .
- Special Property B: It is guaranteed that for any , the induced subgraph with is connected.
For of the testdata, it is guaranteed that , . The graph is guaranteed to be connected, but it is not guaranteed that there are no multiple edges or self-loops.
Translated by ChatGPT 5