Travelling Businessmen Problem

Given a connected undirected graph with mutable node values, answer queries asking the minimum possible difference between the values of two walkers' end cities.

Hard8GraphBFSBinary searchSortingNo attempts yetTime limit2sMemory limit512 MB

Problem

There are NN cities numbered 1 to NN, connected by MM bidirectional roads. Every city is reachable from every other city. City ii has economic value SiS_i.

There are QQ queries to process in order. Each query consists of three integers AiA_i, BiB_i and CiC_i.

If Ai=0A_i = 0, change the economic value of city BiB_i to CiC_i.

If Ai=1A_i = 1, assume two businessmen start in city BiB_i and city CiC_i. They agree on a nonnegative integer XX. On each of the next XX days, each businessman moves to a city adjacent to the one he is in. Staying in place is not allowed, but revisiting cities is allowed. After XX days, consider the absolute difference of the economic values of the two cities they occupy, and minimize it over all choices of XX and all walks. Output that minimum. The two businessmen may finish in the same city. Each query chooses its own XX independently.

Input

The first line contains NN and MM (1N1000001 \le N \le 100000, 1M2000001 \le M \le 200000). The second line contains the economic values S1,S2,,SNS_1, S_2, \dots, S_N (0Si10000000000 \le S_i \le 1000000000). Each of the next MM lines contains two cities uiu_i and viv_i joined by a road (1ui,viN1 \le u_i, v_i \le N, uiviu_i \ne v_i). Every city is reachable from every other city. The next line contains QQ (1Q1000001 \le Q \le 100000). Each of the next QQ lines contains one query AiA_i, BiB_i and CiC_i (0Ai10 \le A_i \le 1). If Ai=0A_i = 0 then 1BiN1 \le B_i \le N and 0Ci10000000000 \le C_i \le 1000000000. If Ai=1A_i = 1 then 1Bi,CiN1 \le B_i, C_i \le N. At least one query has Ai=1A_i = 1.

Output

For each query with Ai=1A_i = 1, print the minimum achievable difference of economic values on its own line. The value of XX is independent between queries.

Hint

Study how the set of reachable cities changes as XX grows. Moving to a neighbor and back extends a walk by 2, so reachability depends on the parity of XX. If the graph has an odd cycle, the two businessmen can always meet in one city. If the graph is bipartite, each businessman stays on the side fixed by the start city and the parity of XX. Two starts on the same side always give 0. Two starts on opposite sides give the closest pair of economic values across the two sides.