当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5266:pog loves szh III

题目描述
Pog and Szh are playing games. Firstly Pog draw a tree on the paper. Here we define 1 as the root of the tree.Then Szh choose some nodes from the tree. He wants Pog helps to find the least common ancestor (LCA) of these node.The question is too difficult for Pog.So he decided to simplify the problems.The nodes picked are consecutive numbers from $l_i$ to $r_i$ $([l_i, r_i])$.

Hint : You should be careful about stack overflow !
输入解释
Several groups of data (no more than 3 groups,$n \geq 10000$ or $Q \geq 10000$).

The following line contains ans integers,$n (2 \leq n \leq 300000)$.

AT The following $n-1$ line, two integers are $b_i$ and $c_i$ at every line, it shows an edge connecting $b_i$ and $c_i$.

The following line contains ans integers,$Q (Q \leq 300000)$.

AT The following $Q$ line contains two integers li and ri($1 \leq li \leq ri \leq n$).
输出解释
For each case,output $Q$ integers means the LCA of $[l_i,r_i]$.
输入样例
5
1 2
1 3
3 4
4 5
5
1 2
2 3
3 4
3 5
1 5
输出样例
1
1
3
3
1


提示
Be careful about stack overflow.
来自杭电HDUOJ的附加信息
Recommend hujie

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 BestCoder Round #43

源链接: HDU-5266

最后修改于 2020-10-25T23:21:11+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
12000/6000MS(Java/Others) 131072/131072K(Java/Others)