Logo
(追記) (追記ここまで)

23868번 - Rooted MST 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 1024 MB259940.909%

문제

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

The weight of an edge between vertices 0ドル$ and $i$ is $a_i$ for 1ドル \leq i \leq n$.

The weight of an edge between vertices $u_i$ and $v_i$ is $w_i$ for 1ドル \leq i \leq m$.

You need to answer $q$ queries, in each query, you are given two integers $i, w$ and you need to change the weight of an edge from 0ドル$ to $i$ to $w$ 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, m$ (2ドル \leq n \leq 300,000,円 0 \leq m \leq 300,000円$).

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ (1ドル \leq a_i \leq 10^9$).

Each of the next $m$ lines contains three integers $u_i, v_i, w_i$ (1ドル \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 $q$ (1ドル \leq q \leq 300,000円$).

Each of the next $q$ lines contains two integers $i, w$ (1ドル \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 $i$ queries.

제한

서브태스크

번호배점제한
110

$n, m, q \leq 2000$

210

All weights are either 1ドル$ or 2ドル$

310

$w = 1$ in all queries

410

$i = 1$ in all queries

510

$i \le 5$ in all queries

610

$m = n - 1, u_i = v_i - 1$

720

$n, m, q \leq 150,000円$

820

No additional constraints

예제 입력 1

5 7
3 2 1 2 1
1 5 1
1 3 2
2 5 2
4 5 2
3 4 1
2 4 2
1 2 1
10
3 2
2 3
4 1
3 2
5 1
5 3
3 1
2 3
4 3
5 1

예제 출력 1

6
6
5
5
5
6
6
6
6
5

힌트

출처

Contest > Innopolis Open in Informatics > Innopolis Open in Informatics, 2020-2021, The Final E번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /