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

8476번 - Highways 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 128 MB51151126.829%

문제

Byteland is a small country, with n cities connected by n-1 bidirectional roads. From each city there is just one way of reaching every other city using the road network, which causes severe traffic jams. For this reason several highways have been built; each highway connects some pair of cities.

By a route we mean a sequence of roads and/or highways. All cities on a route should be distinct. For each pair of cities x, y there exists exactly one route which does not use any highway; we call such a route the main route between x and y.

People going from a city x to a city y can either choose the main route or use some highway. In the latter case the route cannot intersect the main route except for the cities and x and y must contain exactly one highway.

Your task is to calculate the number of routes people can take between given pairs of cities.

입력

The first line of input contains a single integer n (1 ≤ n ≤ 100 000) - the number of cities in Byteland. Cities are numbered from 1 to n. Each of the next n-1 lines contains two integers ai, bi (1 ≤ ai, bi ≤ n) meaning that cities ai and bi are connected by a road.

The next line contains an integer m (1 ≤ m ≤ 100 000) - the number of highways. Each of the next m lines contains a description of a single highway. The next line contains an integer q (1 ≤ q ≤ 500 000) - the number of queries. Each of the next q lines contains a description of a query. Both highways and queries are given in the same format as the roads.

출력

Your program should output exactly q lines. The i-th line should contain the number of routes in the i-th query.

제한

예제 입력 1

9
1 2
2 3
4 2
1 5
5 6
7 5
7 8
9 7
4
2 5
3 4
6 4
8 3
4
4 9
2 5
1 6
1 7

예제 출력 1

1
4
2
2

힌트

출처

Camp > POI Training Camp > ONTAK 2010 5-1번

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

출처

대학교 대회

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

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