Logo
(追記) (追記ここまで)

11738번 - Distance on Triangulation 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB159352727.551%

문제

You have a convex polygon. The vertices of the polygon are successively numbered from 1 to n. You also have a triangulation of this polygon, given as a list of n − 3 diagonals.

You are also given q 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 n — the number of vertices of the polygon (4 ≤ n ≤ 50 000).

Each of the following n−3 lines contains two integers ai, bi — the ends of the i-th diagonal (1 ≤ ai, bi ≤ n, ai ≠ bi).

The next line contains an integer q — the number of queries (1 ≤ q ≤ 100 000).

Each of the following q lines contains two integers xi, yi — the vertices in the i-th query (1 ≤ xi, yi ≤ n).

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

힌트

This is the polygon from the sample input.

출처

ICPC > Regionals > Northern Eurasia > Northern Eurasia Finals > NEERC 2015 D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /