CF1580E.Railway Construction

NOI/NOI+/CTSC

通过率:0%

时间限制:2.50s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Because the railway system in Gensokyo is often congested, as an enthusiastic engineer, Kawasiro Nitori plans to construct more railway to ease the congestion.

There are nn stations numbered from 11 to nn and mm two-way railways in Gensokyo. Every two-way railway connects two different stations and has a positive integer length dd. No two two-way railways connect the same two stations. Besides, it is possible to travel from any station to any other using those railways. Among these nn stations, station 11 is the main station. You can get to any station from any other station using only two-way railways.

Because of the technological limitation, Nitori can only construct one-way railways, whose length can be arbitrary positive integer. Constructing a one-way railway from station uu will costs wuw_u units of resources, no matter where the railway ends. To ease the congestion, Nitori plans that after construction there are at least two shortest paths from station 11 to any other station, and these two shortest paths do not pass the same station except station 11 and the terminal. Besides, Nitori also does not want to change the distance of the shortest path from station 11 to any other station.

Due to various reasons, sometimes the cost of building a new railway will increase uncontrollably. There will be a total of qq occurrences of this kind of incident, and the ii-th event will add additional amount of xix_i to the cost of building a new railway from the station kik_i.

To save resources, before all incidents and after each incident, Nitori wants you to help her calculate the minimal cost of railway construction.

由于幻想乡的铁路系统经常拥堵,作为一位热心的工程师,河城荷取计划修建更多的铁路以缓解拥堵。

幻想乡共有 nn 个车站,编号从 11 到 nn,以及 mm 条双向铁路。每条双向铁路连接两个不同的车站,且具有一个正整数长度 dd。任意两条双向铁路不会连接完全相同的两个车站。此外,仅通过这些双向铁路,任意两个车站之间均可互相到达。在这 nn 个车站中,车站 11 是主车站——即从任意车站出发,均可仅通过双向铁路抵达其余任意车站。

受限于技术条件,荷取只能修建单向铁路,其长度可为任意正整数。从车站 uu 出发修建一条单向铁路的花费为 wuw_u 单位资源,与该铁路的终点无关。为缓解拥堵,荷取计划:在新建铁路完成后,对于任意其他车站 vv,从车站 11 到 vv 至少存在两条最短路径,且这两条最短路径除起点 11 和终点 vv 外,不经过任何相同车站。此外,荷取也不希望改变从车站 11 到任意其他车站的最短路径长度。

由于种种原因,有时新建铁路的建造成本会失控地上涨。此类事件总共会发生 qq 次,其中第 ii 次事件会使从车站 kik_i 出发修建新铁路的成本额外增加 xix_i。

为节约资源,在所有事件发生前,以及每次事件发生后,荷取希望你帮她计算铁路建设的最小总成本。

输入格式

The first line contains three integers nn, mm, and qq (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5, 1≤m≤3⋅1051 \le m \le 3 \cdot 10^5, 0≤q≤2⋅1050 \le q \le 2\cdot10^5).

The second line contains nn integers w1,w2,…,wnw_1,w_2,\ldots,w_n (1≤wi≤1091 \le w_i \le 10^9).

Each of the next mm lines contains three integers uu, vv, dd (1≤u,v≤n1 \le u,v \le n, u≠vu \ne v, 1≤d≤1091 \le d \le 10^9), denoting a two-way railway connecting station uu and station vv, with length dd.

The ii-th of the next qq lines contains two integers ki,xik_i,x_i (1≤ki≤n,1≤xi≤4×1081 \le k_i \le n, 1 \le x_i \le 4 \times 10^8).

第一行包含三个整数 nn、mm 和 qq(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5,1≤m≤3⋅1051 \le m \le 3 \cdot 10^5,0≤q≤2⋅1050 \le q \le 2\cdot10^5)。

第二行包含 nn 个整数 w1,w2,…,wnw_1,w_2,\ldots,w_n(1≤wi≤1091 \le w_i \le 10^9)。

接下来的 mm 行中,每行包含三个整数 uu、vv、dd(1≤u,v≤n1 \le u,v \le n,u≠vu \ne v,1≤d≤1091 \le d \le 10^9),表示一条连接车站 uu 和车站 vv 的双向铁路,其长度为 dd。

接下来的 qq 行中,第 ii 行包含两个整数 kik_i 和 xix_i(1≤ki≤n1 \le k_i \le n,1≤xi≤4×1081 \le x_i \le 4 \times 10^8)。

输出格式

Print q+1q+1 lines, and the ii-th of these lines contains one integer, denoting the minimal cost of railway construction after the i−1i-1-th incident (especially, the 00-th incident means no incident occurred).

输出 q+1q+1 行,其中第 ii 行包含一个整数,表示在第 i−1i-1 次事故(特别地,第 00 次事故表示未发生任何事故)之后铁路建设的最小代价。

输入输出样例

  • 输入#1

    5 5 1
    1 1 1 1 1
    1 2 1
    2 3 1
    2 4 1
    3 5 1
    4 5 1
    1 2

    输出#1

    3
    9
  • 输入#2

    8 11 0
    14 4 16 15 1 3 1 14
    4 2 1
    1 2 3
    7 5 4
    2 3 1
    8 6 2
    8 5 5
    5 4 5
    7 6 7
    3 5 5
    1 6 6
    8 1 4

    输出#2

    46
  • 输入#3

    10 16 8
    29 1 75 73 51 69 24 17 1 97
    1 2 18
    2 3 254
    2 4 546
    2 5 789
    5 6 998
    6 7 233
    7 8 433
    1 9 248
    5 10 488
    2 6 1787
    10 8 1176
    3 8 2199
    4 8 1907
    2 10 1277
    4 10 731
    9 10 1047
    1 11
    1 9
    8 8
    1 3
    2 19
    9 5
    9 4
    7 6

    输出#3

    34
    45
    54
    54
    57
    76
    96
    112
    112

说明/提示

In the second example, Nitori can build railways as follows: 1→21 \rightarrow 2, 1→31 \rightarrow 3, 1→41 \rightarrow 4, 2→82 \rightarrow 8, and the cost is 14+14+14+4=4614 + 14 + 14 + 4 = 46.

在第二个例子中,Nitori 可以按如下方式修建铁路:1→21 \rightarrow 2、1→31 \rightarrow 3、1→41 \rightarrow 4、2→82 \rightarrow 8,总花费为 14+14+14+4=4614 + 14 + 14 + 4 = 46。

输入解题思路,AI测评打分。不知道怎么写?

首页