Pooja and her Backup System

3

11 votes
Medium
Problem

It is known that all people can be divided into two groups: those who have never lost important data and those who regularly perform data backups as taught in OS course. Pooja is on her way from the first group to the second after the incident in which she lost her important data :p . Not satisfied with the existing data backup solutions for various reasons, she decided to design her own backup system. Since errors in such an important system are absolutely unacceptable, Pooja asks you to test the product.

The systems organization is as follows: let there be N computers in a local network. The computers are numbered with integers from 1 to N. Some pairs of computers are connected by cables. For economy, the network doesn’t have unnecessary cables, which means that there is a unique cable path between any two computers. Initially there are bi bytes of information written on the i-th computer. This system can process two types of requests:

1) Copy all the information from computer v to all adjacent computers (i.e., to all computers directly connected to it by a cable) If computer v had xv bytes of information, then, after copying, all adjacent computers will have xv bytes of information more, while computer v will still have xv bytes of information.

2) Output the current amount of information on computer v. As this amount can grow very quickly, output the remainder of its division by the number 109 + 7.
For testing this system, you have to write a program for quick processing of such requests.

Input

The first line contains the number N of computers in the network.
In the second line you are given integers a1, …, aN, which are the amounts of information (in bytes) on the computers at the initial time. Each of the following N − 1 lines contains integers x and y, which mean that the computers with numbers x and y are connected by a cable. It is guaranteed that the network is connected.
The next line contains the number M of requests to the system . In the following M lines you are given the requests in the order of their execution. Each request is a pair of integers t and v , where t specifies the type of the request and v is the number of the computer to which the request is applied.

Output
For each request of the second type, output in a separate line the remainder of the division of the answer by the number 109 + 7.

Constraints
1<=N<=105
0 ≤ ai ≤ 109
1 ≤ x, y ≤ N and x ≠ y
1 ≤ M ≤ 105
1 ≤ t ≤ 2 and 1 ≤ v ≤ N

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?