Rooted MST

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

You are given a simple undirected weighted graph with n+1n+1 vertices numbered 0,1,,n0, 1, \ldots, n and n+mn + m edges.

The weight of an edge between vertices 00 and ii is a_ia\_i for 1in1 \leq i \leq n.

The weight of an edge between vertices u_iu\_i and v_iv\_i is w_iw\_i for 1im1 \leq i \leq m.

You need to answer qq queries, in each query, you are given two integers i,wi, w and you need to change the weight of an edge from 00 to ii to ww and find the weight of the minimum spanning tree in the graph. 

Note that changes to the weights are permanent, i.e. they stay after each query.

입력

The first line of input contains two numbers n,mn, m (2n300,000,0m300,0002 \leq n \leq 300\\,000, 0 \leq m \leq 300\\,000).

The second line contains nn integers a_1,a_2,,a_na\_1, a\_2, \ldots, a\_n (1a_i1091 \leq a\_i \leq 10^9).

Each of the next mm lines contains three integers u_i,v_i,w_iu\_i, v\_i, w\_i (1u_i,v_in,0w_i1091 \leq u\_i, v\_i \leq n, 0 \leq w\_i \leq 10^9).

It is guaranteed that the given graph is simple, in other words, it contains no loops and multiple edges.

The next line contains one integer qq (1q300,0001 \leq q \leq 300\\,000).

Each of the next qq lines contains two integers i,wi, w (1in,1w1091 \leq i \leq n, 1 \leq w \leq 10^9).

출력

For each query print one integer: the weight of the minimum spanning tree in the graph after the first ii queries.