F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Sometimes Naive

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 870    Accepted Submission(s): 336


Problem Description
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$
 

Input
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)$
 

Output
For each test case, print the answer for each query operation.
 

Sample Input
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
 

Sample Output
341 348 612
 

Author
xudyh
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-21 18:29:34, Gzip enabled