Big Problems for Organizers

题意翻译

# 题目描述 “俄罗斯编程杯2214”的总决赛将在$n$个酒店,$2$个酒店(我们假设这两个酒店是主酒店)将主持各种活动,而其他$n-2$个酒店将容纳所有参赛者。这些酒店被$n-1$条路连接着,你可以从任意一个酒店去往任意另外一个酒店。 组织者们想知道,最少需要多少时间,能够让所有参赛者从他们的酒店去往主酒店(每个参与者都去离他最近的主酒店),假设在两家由道路连接的旅馆之间走动需要$1$个单位的时间。 主持人知道每个酒店的位置,对于每个询问,帮助主持人找到最短距离。 # 输入输出格式 ## 输入 输入共$n+m+1$行。第一行输入酒店的个数$n(2<=n<=10^5)$。接下来$n-1$行,每一行输入两个整数——两个酒店的位置(保证在它们之间有一条路),酒店从$1$到$n$标了号。 接下来一行输入询问的次数$m(1<=n<=10^5)$,接下来的$m$行,每一行代表着两个主酒店的位置。 ## 输出 输出共$m$行,每一行输出对应的结果,表示从其他旅馆进到主旅馆的时间。 @[chen_zhe](/space/show?uid=8457) @[yjjr](/space/show?uid=5088) @[龟龟号打捞船](/space/show?uid=36482)

题目描述

The Finals of the "Russian Code Cup" 2214 will be held in $ n $ hotels. Two hotels (let's assume that they are the main hotels), will host all sorts of events, and the remaining hotels will accommodate the participants. The hotels are connected by $ n-1 $ roads, you can get from any hotel to any other one. The organizers wonder what is the minimum time all the participants need to get to the main hotels, if each participant goes to the main hotel that is nearest to him and moving between two hotels connected by a road takes one unit of time. The hosts consider various options for the location of the main hotels. For each option help the organizers to find minimal time.

输入输出格式

输入格式


The first line contains an integer $ n $ ( $ 2<=n<=100000 $ ) — the number of hotels. The next $ n-1 $ lines contain two integers each — the numbers of the hotels that have a road between them. Consider hotels are numbered from $ 1 $ to $ n $ . The next line contains an integer $ m $ ( $ 1<=m<=100000 $ ) — the number of queries. The following $ m $ lines contains two distinct integers each — the numbers of the hotels we assume to be the main.

输出格式


For each request of the organizers print a single integer — the time that all participants need to reach the main hotels.

输入输出样例

输入样例 #1

3
2 3
3 1
3
2 1
2 3
3 1

输出样例 #1

1
1
1

输入样例 #2

4
1 4
1 2
2 3
3
1 4
1 3
2 3

输出样例 #2

2
1
2