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

建议使用的浏览器:

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

5405:Sometimes Naive

题目描述
Rhason Cheung had a naive problem, and asked Teacher Mai for help. But Teacher Mai thought this problem was too simple, sometimes naive. So she ask you for help.

She has a tree with $n$ vertices, numbered from $1$ to $n$. The weight of $i$-th node is $w_i$.

You need to support two kinds of operations: modification and query.

For a modification operation $u,w$, you need to change the weight of $u$-th node into $w$.

For a query operation $u,v$, you should output $\sum_{i=1}^n \sum_{j=1}^n f(i,j)$. If there is a vertex on the path from $u$ to $v$ and the path from $i$ to $j$ in the tree, $f(i,j)=w_iw_j$, otherwise $f(i,j)=0$. The number can be large, so print the number modulo $10^9+7$
输入解释
There are multiple test cases.

For each test case, the first line contains two numbers $n,m(1\leq n,m\leq 10^5)$.

There are $n$ numbers in the next line, the $i$-th means $w_i(0\leq w_i\leq 10^9)$.

Next $n-1$ lines contain two numbers each, $u_i$ and $v_i$, that means that there is an edge between $u_i$ and $v_i$.

The following are $m$ lines. Each line indicates an operation, and the format is "$1~u~w$"(modification) or "$2~u~v$"(query)$(0\leq w\leq 10^9)$
输出解释
For each test case, print the answer for each query operation.
输入样例
6 5
1 2 3 4 5 6
1 2
1 3
2 4
2 5
4 6
2 3 5
1 5 6
2 2 3
1 1 7
2 2 4
输出样例
341
348
612
来自杭电HDUOJ的附加信息
Author xudyh
Recommend wange2014

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

源链接: HDU-5405

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

共提交 0

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