CF1433G.Reducing Delivery Cost
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are a mayor of Berlyatov. There are n districts and m two-way roads between them. The i -th road connects districts xi and yi . The cost of travelling along this road is wi . There is some path between each pair of districts, so the city is connected.
There are k delivery routes in Berlyatov. The i -th route is going from the district ai to the district bi . There is one courier on each route and the courier will always choose the cheapest (minimum by total cost) path from the district ai to the district bi 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 0 ).
Let d(x,y) be the cheapest cost of travel between districts x and y .
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 0 . In other words, you have to find the minimum possible value of i=1∑kd(ai,bi) after applying the operation described above optimally.
输入格式
The first line of the input contains three integers n , m and k ( 2≤n≤1000 ; n−1≤m≤min(1000,2n(n−1)) ; 1≤k≤1000 ) — the number of districts, the number of roads and the number of courier routes.
The next m lines describe roads. The i -th road is given as three integers xi , yi and wi ( 1≤xi,yi≤n ; xi=yi ; 1≤wi≤1000 ), where xi and yi are districts the i -th road connects and wi 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 k lines describe courier routes. The i -th route is given as two integers ai and bi ( 1≤ai,bi≤n ) — the districts of the i -th route. The route can go from the district to itself, some couriers routes can coincide (and you have to count them independently).
输出格式
Print one integer — the minimum total courier routes cost you can achieve (i.e. the minimum value i=1∑kd(ai,bi) , where d(x,y) is the cheapest cost of travel between districts x and y ) if you can make some (at most one) road cost zero.
输入输出样例
输入#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) or the road (4,6) . Both options lead to the total cost 22 .
The picture corresponding to the second example:
There, you can choose the road (3,4) . This leads to the total cost 13 .