#P6976. [NEERC 2015] Distance on Triangulation
[NEERC 2015] Distance on Triangulation
Description
You have a convex polygon. The vertices of the polygon are successively numbered from to . You also have a triangulation of this polygon, given as a list of diagonals.
You are also given queries. Each query consists of two vertex indices. For each query, find the shortest distance between these two vertices, provided that you can move by the sides and by the given diagonals of the polygon, and the distance is measured as the total number of sides and diagonals you have traversed.
Input Format
The first line of the input file contains an integer -- the number of vertices of the polygon .
Each of the following lines contains two integers -- the ends of the i-th diagonal
The next line contains an integer -- the number of queries .
Each of the following lines contains two integers -- the vertices in the i-th query .
It is guaranteed that no diagonal coincides with a side of the polygon, and that no two diagonals coincide or intersect.
Output Format
For each query output a line containing the shortest distance.
6
1 5
2 4
5 2
5
1 3
2 5
3 4
6 3
6 6
2
1
1
3
0
Hint
Time limit: 2 s, Memory limit: 256 MB.
京公网安备 11011102002149号