CF1433G.Reducing Delivery Cost

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are a mayor of Berlyatov. There are nn districts and mm two-way roads between them. The ii-th road connects districts xix_i and yiy_i. The cost of travelling along this road is wiw_i. There is some path between each pair of districts, so the city is connected.

There are kk delivery routes in Berlyatov. The ii-th route is going from the district aia_i to the district bib_i. There is one courier on each route and the courier will always choose the cheapest (minimum by total cost) path from the district aia_i to the district bib_i to deliver products.

The route can go from the district to itself, some couriers routes can coincide (and you have to count them independently).

You can make at most one road to have cost zero (i.e. you choose at most one road and change its cost with 00).

Let d(x,y)d(x, y) be the cheapest cost of travel between districts xx and yy.

Your task is to find the minimum total courier routes cost you can achieve, if you optimally select the some road and change its cost with 00. In other words, you have to find the minimum possible value of ∑i=1kd(ai,bi)\sum\limits_{i = 1}^{k} d(a_i, b_i) after applying the operation described above optimally.

你是一名贝利亚托夫市的市长。该市共有 nn 个区和 mm 条双向道路连接这些区。第 ii 条道路连接区 xix_i 和 yiy_i,通行成本为 wiw_i。任意两个区之间均存在路径,因此该城市是连通的。

贝利亚托夫市共有 kk 条快递运输路线。第 ii 条路线从区 aia_i 出发,到达区 bib_i。每条路线上均有一名快递员,且该快递员总是选择总成本最低(即最短路径)的路线,从区 aia_i 前往区 bib_i 完成配送任务。

路线允许起点与终点为同一区(即 ai=bia_i = b_i),不同快递员的路线可能重合(此时需独立计数)。

你最多可将一条道路的成本设为零(即:你至多选择一条道路,并将其通行成本修改为 00)。

令 d(x,y)d(x, y) 表示区 xx 与区 yy 之间的最低通行成本。

你的任务是:在最优地选择至多一条道路并将其成本设为 00 后,使得所有快递路线的总成本 ∑i=1kd(ai,bi)\sum\limits_{i = 1}^{k} d(a_i, b_i) 达到最小。请找出该最小可能值。

输入格式

The first line of the input contains three integers nn, mm and kk (2≤n≤10002 \le n \le 1000; n−1≤m≤min(1000,n(n−1)2)n - 1 \le m \le min(1000, \frac{n(n-1)}{2}); 1≤k≤10001 \le k \le 1000) — the number of districts, the number of roads and the number of courier routes.

The next mm lines describe roads. The ii-th road is given as three integers xix_i, yiy_i and wiw_i (1≤xi,yi≤n1 \le x_i, y_i \le n; xi≠yix_i \ne y_i; 1≤wi≤10001 \le w_i \le 1000), where xix_i and yiy_i are districts the ii-th road connects and wiw_i is its cost. It is guaranteed that there is some path between each pair of districts, so the city is connected. It is also guaranteed that there is at most one road between each pair of districts.

The next kk lines describe courier routes. The ii-th route is given as two integers aia_i and bib_i (1≤ai,bi≤n1 \le a_i, b_i \le n) — the districts of the ii-th route. The route can go from the district to itself, some couriers routes can coincide (and you have to count them independently).

输入的第一行包含三个整数 nn、mm 和 kk(2≤n≤10002 \le n \le 1000;n−1≤m≤min⁡(1000,n(n−1)2)n - 1 \le m \le \min(1000, \frac{n(n-1)}{2});1≤k≤10001 \le k \le 1000),分别表示行政区的数量、道路的数量以及快递路线的数量。

接下来的 mm 行描述道路。第 ii 条道路由三个整数 xix_i、yiy_i 和 wiw_i(1≤xi,yi≤n1 \le x_i, y_i \le n;xi≠yix_i \ne y_i;1≤wi≤10001 \le w_i \le 1000)给出,其中 xix_i 和 yiy_i 是该道路所连接的两个行政区,wiw_i 是该道路的费用。保证任意两个行政区之间均存在路径,即整个城市是连通的。同时保证任意两个行政区之间至多只有一条道路。

接下来的 kk 行描述快递路线。第 ii 条路线由两个整数 aia_i 和 bib_i(1≤ai,bi≤n1 \le a_i, b_i \le n)给出,表示该路线的起止行政区。路线允许起点与终点为同一行政区;部分快递路线可能完全相同(需独立计数)。

输出格式

Print one integer — the minimum total courier routes cost you can achieve (i.e. the minimum value ∑i=1kd(ai,bi)\sum\limits_{i=1}^{k} d(a_i, b_i), where d(x,y)d(x, y) is the cheapest cost of travel between districts xx and yy) if you can make some (at most one) road cost zero.

输出一个整数——在最多将一条道路的费用设为 0 的前提下,所能达到的快递员总路线费用的最小值(即最小化 ∑i=1kd(ai,bi)\sum\limits_{i=1}^{k} d(a_i, b_i),其中 d(x,y)d(x, y) 表示从区域 xx 到区域 yy 的最便宜通行费用)。

输入输出样例

  • 输入#1

    6 5 2
    1 2 5
    2 3 7
    2 4 4
    4 5 2
    4 6 8
    1 6
    5 3

    输出#1

    22
  • 输入#2

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

    输出#2

    13

说明/提示

The picture corresponding to the first example:

There, you can choose either the road (2,4)(2, 4) or the road (4,6)(4, 6). Both options lead to the total cost 2222.

The picture corresponding to the second example:

There, you can choose the road (3,4)(3, 4). This leads to the total cost 1313.

第一个示例对应的图:

在此图中,你可以选择道路 (2,4)(2, 4) 或道路 (4,6)(4, 6)。两种选择均导致总代价为 2222。

第二个示例对应的图:

在此图中,你可以选择道路 (3,4)(3, 4)。这将导致总代价为 1313。

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

首页