CF449B.Jzzhu and Cities

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city u__i to v__i (and vise versa) using the i-th road, the length of this road is x__i. Finally, there are k train routes in the country. One can use the i-th train route to go from capital of the country to city s__i (and vise versa), the length of this route is y__i.

Jzzhu doesn't want to waste the money of the country, so he is going to close some of the train routes. Please tell Jzzhu the maximum number of the train routes which can be closed under the following condition: the length of the shortest path from every city to the capital mustn't change.

Jzzhu 是 A 国的总统。他的国家中有 nn 座城市,编号从 11 到 nn。其中城市 11 是 A 国的首都。此外,有 mm 条道路连接这些城市。通过第 ii 条道路,可以从城市 uiu_i 到达城市 viv_i(反之亦然),该道路的长度为 xix_i。最后,国内还有 kk 条铁路线路。通过第 ii 条铁路线路,可以从首都到达城市 sis_i(反之亦然),该线路的长度为 yiy_i。

Jzzhu 不想浪费国家的资金,因此他打算关闭部分铁路线路。请告诉 Jzzhu:在满足如下条件的前提下,最多可以关闭多少条铁路线路?即:每座城市到首都的最短路径长度不得改变。

输入格式

The first line contains three integers n, m, k (2 ≤ n ≤ 105; 1 ≤ m ≤ 3·105; 1 ≤ k ≤ 105).

Each of the next m lines contains three integers u__i, v__i, x__i (1 ≤ u__i, v__i ≤ n; u__i ≠ v__i; 1 ≤ x__i ≤ 109).

Each of the next k lines contains two integers s__i and y__i (2 ≤ s__i ≤ n; 1 ≤ y__i ≤ 109).

It is guaranteed that there is at least one way from every city to the capital. Note, that there can be multiple roads between two cities. Also, there can be multiple routes going to the same city from the capital.

第一行包含三个整数 nn、mm、kk(2≤n≤1052 \leq n \leq 10^5;1≤m≤3⋅1051 \leq m \leq 3 \cdot 10^5;1≤k≤1051 \leq k \leq 10^5)。

接下来的 mm 行,每行包含三个整数 uiu_i、viv_i、xix_i(1≤ui,vi≤n1 \leq u_i, v_i \leq n;ui≠viu_i \neq v_i;1≤xi≤1091 \leq x_i \leq 10^9)。

接下来的 kk 行,每行包含两个整数 sis_i 和 yiy_i(2≤si≤n2 \leq s_i \leq n;1≤yi≤1091 \leq y_i \leq 10^9)。

保证从每个城市到首都至少存在一条路径。注意,两座城市之间可能存在多条道路;同样,从首都到同一座城市的路径也可能有多条。

输出格式

Output a single integer representing the maximum number of the train routes which can be closed.

输出一个整数,表示最多可以关闭的火车线路数量。

输入输出样例

  • 输入#1

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

    输出#1

    2
  • 输入#2

    2 2 3
    1 2 2
    2 1 3
    2 1
    2 2
    2 3

    输出#2

    2

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

首页