시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
4 초 | 512 MB | 27 | 11 | 10 | 38.462% |
There is a rooted tree. Each vertex contains some non-negative amount of charge cv. You have to process three kinds of queries:
At the end, you should print the value of charge in each vertex.
In the first line of input there is a single integer n, the number of vertices in the tree (2 ≤ n ≤ 500 000).
The next line contains n integers ci, i-th of them denoting the initial charge of the tree (0 ≤ ci < 109 + 7).
Each of the next n − 1 lines contains two integers ui and vi denoting the edge between vertices ui and vi (1 ≤ ui, vi ≤ n).
Next line contain a single integer q, the number of queries (0 ≤ q ≤ 500 000). Then q lines follow with the description of queries. “Move up” query is denoted with a character “ˆ”. “Move down” query is denoted with a character “v”. “Add charge” query is denoted with a character “+” followed by two integers vi and xi, meaning that you should add charge xi to vertex vi (1 ≤ vi ≤ n, 0 ≤ xi < 109 + 7).
It is guaranteed that the graph in the input is a tree.
Print n numbers, i-th of them being the final charge of vertex i modulo 109 + 7.
Formally, let the charge be p/q. Then you should print a unique number x, 0 ≤ x < 109 + 7, such that p ≡ x · q mod 109 + 7.
5 4 3 3 6 0 1 2 1 3 2 4 4 5 5 v + 1 7 ^ + 2 1 v
0 500000009 500000009 4 6
2 5 10 1 2 5 v v v ^ ^
0 5
4 0 1 0 0 1 2 1 3 1 4 2 ^ v
0 333333336 333333336 333333336