题目链接

B. Jzzhu and Cities
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 mroads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. 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 si (and vise versa), the length of this route is yi.

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.

Input

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 ui, vi, xi (1 ≤ ui, vi ≤ nui ≠ vi; 1 ≤ xi ≤ 109).

Each of the next k lines contains two integers si and yi (2 ≤ si ≤ n; 1 ≤ yi ≤ 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.

Output

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

Sample test(s)
input
5 5 3
1 2 1
2 3 2
1 3 3
3 4 4
1 5 5
3 5
4 5
5 5
output
2
input
2 2 3
1 2 2
2 1 3
2 1
2 2
2 3
output
2

 /*************************************************************************
> File Name: 449B.cpp
> Author: Stomach_ache
> Mail: sudaweitong@gmail.com
> Created Time: 2014年07月20日 星期日 10时17分44秒
> Propose:
************************************************************************/
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <fstream>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; #define X first
#define Y second
const int maxn = ;
typedef long long LL;
typedef pair<LL, int> pii;
LL d[maxn];
int n, m, k;
bool done[maxn];
vector<pii> G[maxn]; void
dijkstra() {
priority_queue<pii> q;
d[] = ;
for (int i = ; i < n; i++) if (d[i] != 1e15) q.push(pii(-d[i], i));
//memset(done, false, sizeof(done));
while (!q.empty()) {
pii cur = q.top();
q.pop();
int r = -cur.X;
int u = cur.Y;
if (r != d[u]) continue;
for (unsigned i = ; i < G[u].size(); i++) {
int v = G[u][i].X;
if (d[v] > d[u] + G[u][i].Y) {
d[v] = d[u] + G[u][i].Y;
q.push(pii(-d[v], v));
}
}
} return ;
} int
main(void) {
ios::sync_with_stdio(false);
cin >> n >> m >> k;
for (int i = ; i < m; i++) {
int u, v, x;
cin >> u >> v >> x;
u--, v--;
G[u].push_back(pii(v, x));
G[v].push_back(pii(u, x));
}
for (int i = ; i < n; i++) d[i] = 1e15;
for (int i = ; i < k; i++) {
int s, y;
cin >> s >> y;
s--;
d[s] = min(d[s], y*1LL);
}
dijkstra(); int res = ;
for (int i = ; i < n; i++) {
int t = ;
for (unsigned j = ; j < G[i].size(); j++) {
if (d[i] == d[G[i][j].X] + G[i][j].Y) {
t = ;
break;
}
}
  res += t;
}
cout << k - res << endl; return ;
}




												

Codeforces 449B的更多相关文章

  1. [Codeforces 449B] Jzzhu and Cities

    [题目链接] https://codeforces.com/contest/449/problem/B [算法] 最短路 时间复杂度 : O(N ^ 2) [代码] #include<bits/ ...

  2. codeforces 449B Jzzhu and Cities (Dij+堆优化)

    输入一个无向图<V,E>    V<=1e5, E<=3e5 现在另外给k条边(u=1,v=s[k],w=y[k]) 问在不影响从结点1出发到所有结点的最短路的前提下,最多可以 ...

  3. Codeforces Round #257 (Div. 1) (Codeforces 449B)

    题意:给力一张无向图,有一些边是正常道路,有一些边是铁路,问最多能删除几条铁路使得所有点到首都(编号为1)的最短路长度不变. 思路:求不能删除的铁路数,总数减掉就是答案.先求出首都到所有点的最短路,求 ...

  4. CodeForces - 449B 最短路(迪杰斯特拉+堆优化)判断最短路路径数

    题意: 给出n个点m条公路k条铁路. 接下来m行 u v w      //u->v 距离w 然后k行 v w         //1->v 距离w 如果修建了铁路并不影响两点的最短距离, ...

  5. Codeforces C. Jzzhu and Cities(dijkstra最短路)

    题目描述: Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  6. 专题:CF图论杂题

    题目是来自HZW的博客(构造题我是各种不会...) Solved 1 / 1 A CodeForces 500A New Year Transportation Solved 1 / 1 B Code ...

  7. CCPC-Wannafly Summer Camp 2019 Day1

    A - Jzzhu and Cities CodeForces - 449B 题意:n座城市,m条路,k条铁路啥的吧,然后要求最多能删多少条铁路保持1到$n$的最短路不变. 思路:因为铁路是从1出发的 ...

  8. Aizu 2249 & cf 449B

    Aizu 2249 & cf 449B 1.Aizu - 2249 选的边肯定是最短路上的. 如果一个点有多个入度,取价值最小的. #include<bits/stdc++.h> ...

  9. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

随机推荐

  1. 《DSP using MATLAB》Problem 8.8

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  2. 网络结构解读之inception系列三:BN-Inception(Inception V2)

    网络结构解读之inception系列三:BN-Inception(Inception V2) BN的出现大大解决了训练收敛问题.作者主要围绕归一化的操作做了一系列优化思路的阐述,值得细看. Batch ...

  3. HZOI20190902模拟35题解

    题面: A:公园 DAG上想拓扑dp 然而博主记忆化搜索了一下 设f[i][j]表示从i节点走j个点出公园所用的最小时间 则$f[u][i]=min(f[v][j-1]+dis_{u,v})$; 然后 ...

  4. HZOI20190722 B visit 组合数+CRT合并

    题目:https://www.cnblogs.com/Juve/articles/11226266.html solution: 30%:dp 设dp[k][i][j]表示经过k时间,在(i,j)的方 ...

  5. MICROSOFT SQL SERVER 2012 序列号

    MICROSOFT SQL SERVER DEVELOPER 版(开发版) 序列号:YQWTX-G8T4R-QW4XX-BVH62-GP68Y MICROSOFT SQL SERVER ENTERPR ...

  6. PHP实现微信退款的分析与源码实现

    原文:https://blog.csdn.net/jason19905/article/details/78628349 网上的很多PHP微信支付接入教程都颇为复杂,且需要配置和引入较多的文件,本人通 ...

  7. 出现大量rcuob进程

    方法一: vim /etc/default/grub,在GRUB_CMDLINE_LINUX这一行末尾添加nr_cpus=2,然后执行命令grub2-mkconfig -o /boot/grub2/g ...

  8. Some vulnerabilities in JEECMSV9

    转载:https://blog.csdn.net/weixin_44063566/article/details/88897406 之前遇到了一个JEECMS大概看了一下, 测试版本JEECMSV9. ...

  9. 【DM642学习笔记十】DSP优化记录

    1. 处理的数据先EDMA到片内,具有更高的效率! 以YUV2RGB为例: #pragma DATA_SECTION(onchipBuf0_y,".INTPROCBUFF"); # ...

  10. redis键(key)

    redis键: 用于管理redis的键 command key_name > set runoodkey redis OK > del runoodkey 上面的例子中,del是一个命令, ...