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

建议使用的浏览器:

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

5735:Born Slippy

题目描述
Professor Zhang has a rooted tree, whose vertices are conveniently labeled by $1,2,...,n$. And the $i$-th vertex is assigned with weight $w_i$.

For each $s \in \{1,2,...,n\}$, Professor Zhang wants find a sequence of vertices $v_1,v_2,...,v_m$ such that:

1. $v_1=s$ and $v_i$ is the ancestor of $v_{i-1}$ $(1 < i \le m)$.
2. the value $f(s)=w_{v_1}+\sum\limits_{i=2}^{m}w_{v_i} \text{ opt } w_{v_{i-1}}$ is maximum. Operation $x \text{ opt } y$ denotes bitwise AND, OR or XOR operation of two numbers.
输入解释
There are multiple test cases. The first line of input contains an integer $T$, indicating the number of test cases. For each test case:

The first line contains an integer $n$ and a string $opt$ $(2 \le n \le 2^{16}, opt \in \{\text{AND}, \text{OR}, \text{XOR}\}$) -- the number of vertices and the operation. The second line contains $n$ integers $w_1,w_2,...,w_n$ $(0 \le w_i < 2^{16})$. The thrid line contain $n-1$ integers $f_2,f_3,...,f_n$ $(1 \le f_i < i)$, where $f_i$ is the father of vertex $i$.

There are about $300$ test cases and the sum of $n$ in all the test cases is no more than $10^6$.
输出解释
For each test case, output an integer $S=(\sum\limits_{i=1}^{n}{i \cdot f(i)}) \text{ mod } (10^9 + 7)$.
输入样例
3
5 AND
5 4 3 2 1
1 2 2 4
5 XOR
5 4 3 2 1
1 2 2 4
5 OR
5 4 3 2 1
1 2 2 4
输出样例
91
139
195
来自杭电HDUOJ的附加信息
Author zimpha
Recommend wange2014

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

源链接: HDU-5735

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

共提交 0

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