logo AlgoBeat OnlineJudge
登录 注册

#206134. [NEERC 2015] Distance on Triangulation

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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.

输入格式

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.

输出格式

For each query output a line containing the shortest distance.

样例

样例输入 1

6
1 5
2 4
5 2
5
1 3
2 5
3 4
6 3
6 6

样例输出 1

2
1
1
3
0

数据范围与提示

Time limit: 2 s, Memory limit: 256 MB.