시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 18 | 7 | 7 | 38.889% |
There are N cities (numbered from 1 to N) connected by M bidirectional roads such that from any city, it is possible to reach any other cities with one or more roads. The i-th city has an economic value of Si, and each road directly connects two different cities.
There are Q queries, which should be executed one by one, each represented by a tuple (Ai, Bi, Ci).
The first line contains two integers: N M (1 ≤ N ≤ 100,000; 1 ≤ M ≤ 200,000) in a line denoting the number of cities and roads. The second line contains N integers: S1 S2 ... SN (0 ≤ Si ≤ 1,000,000,000) in a line denoting the economic value of each city. The next M following lines, each contains two integers: ui vi (1 ≤ ui, vi ≤ N; ui ≠ vi) in a line, which means the i-th road connects city ui and city vi. It is guaranteed that from any city, it is possible to reach any other cities by using one or more roads. The next line contains an integer: Q (1 ≤ Q ≤ 100,000) denoting the number of queries. The next Q lines, each contains three integers: Ai Bi Ci (0 ≤ Ai ≤ 1) in a line denoting the queries. For each query, if Ai = 0, then 1 ≤ Bi ≤ N and 0 ≤ Ci ≤ 1,000,000,000; otherwise 1 ≤ Bi, Ci ≤ N. There will be at least one query where Ai = 1.
For each query where Ai = 1, output the minimum difference of the economic value of the two cities that can be reached by the businessmen after X days, in a line. Note that the value of X is any nonnegative integer and independent between different queries.
6 6 0 0 0 0 0 0 1 2 1 6 5 1 2 3 3 4 3 5 7 1 1 2 0 1 10 0 3 20 1 1 2 0 4 11 1 1 3 1 1 6
0 10 0 1
Explanation for the 1st sample case
The following are the road configuration and the queries for the first sample:
ICPC > Regionals > Asia Pacific > Indonesia > Jakarta > ACM-ICPC Regional Contest, Jakarta 2017 B번