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

建议使用的浏览器:

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

5111:Alexandra and Two Trees

题目描述
Alexandra and her little brother have two rooted trees. For each tree, node 1 is the root, and every other node has its father's index less than itself. Also, there are weights on the nodes. Two nodes in different trees can have the same weight, buf two nodes in the same tree can't.
Now given the two trees and Q queries. Each query follows the format "u1 v1 u2 v2". Let S1 be the set of all node weights on the paths between u1 and v1 on the first tree, S2 be the set of all node weights on the paths between u2 and v2 on the second tree. You should output the number of elements in both S1 and S2. (e.g. the size of the intersection of S1 and S2)
输入解释
There are multiple test cases (no more than 50).
For each case, the first three lines describe the first tree. The first line only contains an integer N, the number of the nodes.
The second line contains N-1 integers, the i-th number is the father of node i+1.
The third line contains N integers, the i-th number is the weight of node i.
Next three lines have the same format, describing the second tree.
Next line only contains an integer Q.
Next Q lines, each line contains four integers u1,v1,u2,v2.
$1 \leq N1, N2 \leq 100,000$.
For each tree, $1 \leq P_i < i, \text{where }i > 1$ and $P_i$ is the father of i.
For each node, $0 \leq \text{weight} \leq 1,000,000,000$.
$1 \leq Q \leq 50,000$.
$1 \leq u_1, v_1 \leq N_1, 1 \leq u_2, v_2 \leq N_2$.
Number of cases with $max(N1,N2,Q) \geq 1,000$ is no more than 5.
Huge data. Fast I/O may be needed.
输出解释
For each query, output the requested answer.
输入样例
3
1 2
1 2 3
3
1 2
1 2 3
3
1 2 1 2
1 2 1 3
1 2 2 3
1

1
1

1
1
1 1 1 1
输出样例
2
2
1
1
来自杭电HDUOJ的附加信息
Recommend heyang

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

题目来源 BestCoder Round #19

源链接: HDU-5111

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

共提交 0

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