RCC 2014 Warmup (Div. 1)
D
Big Problems for Organizers
Codeforces
2800
原题
← CE →
翻译中…

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.

翻译中…

Input

翻译中…

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.

翻译中…

Output

翻译中…

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

翻译中…

样例

Input #1
3
2 3
3 1
3
2 1
2 3
3 1
Output #1
1
1
1
InputCopy OutputCopy
Input #2
4
1 4
1 2
2 3
3
1 4
1 3
2 3
Output #2
2
1
2
InputCopy OutputCopy
题目信息
题号
418D
时间限制
2 s
内存限制
256 MB
标签
数据结构
图论
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。