Codeforces Round 294 (Div. 2)
E
A and B and Lecture Rooms
Codeforces
2100
原题
← D→
翻译中…

A and B are preparing themselves for programming contests.

翻译中…

The University where A and B study is a set of rooms connected by corridors. Overall, the University has $*n*$ rooms connected by $*n* - 1$ corridors so that you can get from any room to any other one by moving along the corridors. The rooms are numbered from $1$ to $*n*$.

翻译中…

Every day А and B write contests in some rooms of their university, and after each contest they gather together in the same room and discuss problems. A and B want the distance from the rooms where problems are discussed to the rooms where contests are written to be equal. The distance between two rooms is the number of edges on the shortest path between them.

翻译中…

As they write contests in new rooms every day, they asked you to help them find the number of possible rooms to discuss problems for each of the following $*m*$ days.

翻译中…

Input

翻译中…

The first line contains integer $*n*$ ($1 ≤ *n* ≤ 10^{5}$) — the number of rooms in the University.

翻译中…

The next $*n* - 1$ lines describe the corridors. The $*i*$-th of these lines ($1 ≤ *i* ≤ *n* - 1$) contains two integers $*a*_{*i*}$ and $*b*_{*i*}$ ($1 ≤ *a*_{*i*}, *b*_{*i*} ≤ *n*$), showing that the $*i*$-th corridor connects rooms $*a*_{*i*}$ and $*b*_{*i*}$.

翻译中…

The next line contains integer $*m*$ ($1 ≤ *m* ≤ 10^{5}$) — the number of queries.

翻译中…

Next $*m*$ lines describe the queries. The $*j*$-th of these lines ($1 ≤ *j* ≤ *m*$) contains two integers $*x*_{*j*}$ and $*y*_{*j*}$ ($1 ≤ *x*_{*j*}, *y*_{*j*} ≤ *n*$) that means that on the $*j*$-th day A will write the contest in the room $*x*_{*j*}$, B will write in the room $*y*_{*j*}$.

翻译中…

Output

翻译中…

In the $*i*$-th ($1 ≤ *i* ≤ *m*$) line print the number of rooms that are equidistant from the rooms where A and B write contest on the $*i*$-th day.

翻译中…

Note

翻译中…

in the first sample there is only one room at the same distance from rooms number 2 and 3 — room number 1.

翻译中…

样例

Input #1
4
1 2
1 3
2 4
1
2 3
Output #1
1
InputCopy OutputCopy
Input #2
4
1 2
2 3
2 4
2
1 2
1 3
Output #2
0
2
InputCopy OutputCopy
题目信息
题号
519E
时间限制
2 s
内存限制
256 MB
标签
二分
数据结构
DFS 及类似
动态规划
树

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