题目链接

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. 使用Java代码获取Java进程ID的方法

    需要jre/lib下的tools.jar包 public class Test { public static void main(String[] args) throws Exception {  ...

  2. eclipse memory analyzer对系统内存溢出堆文件解析(转)

    本文转之:https://blog.csdn.net/rachel_luo/article/details/8992461 前言 性能分析工具之-- Eclipse Memory Analyzer t ...

  3. 慢日志:mysqlsla

    Linux服务器收集到的慢日志文件拿到本地(Windows7)的虚拟机(CentOS6.5)中去分析.首先使用Samba工具配置CentOS和Windows文件共享,然后使用mysqlsla分析慢查询 ...

  4. RocketMQ补偿方案架构设计

    RocketMQ作为消息中间件,在系统异步化架构中,应用非常广泛.但是我们在享用RocketMQ的同时,也不能百分百完全信赖它.一旦RocketMQ崩溃了,给我们业务带来的也将是毁灭性打击. 因此,我 ...

  5. 将ERF格式转换成PCAP格式

    在研究网络流量分析的时候,wireshark默认采用pcap格式.对于用Endace DAG捕捉卡捕获的数据包,一般来说,都是erf格式的.一般来说,此种格式包含了更多了链路层信息.而我们采用wire ...

  6. Errors were encountered while processing: mysql-server-5.5

    ubuntu 中运行完sudo apt-get install curl之后,最后出现: ldconfig deferred processing now taking place Errors we ...

  7. select有条件in要按照in中的数据排序

    mybatis中的写法 <select id="selectByIds" resultType="com.hoohui.electronic.util.ExHash ...

  8. jeecms框架单点登录功能的实现

    单点登录的功能实现主要原理: 1: 在点击登录按钮的时候使用reponse.addCookie()方法向浏览器发送cookie: 2: 在前段拦截器中的request.getCookie()在接收到设 ...

  9. MyBatis-Spring(三)--Mapped Statements collection does not contain value for...问题解决

    前一篇文章我总结了一下MyBatis-Spring项目使用SqlSessionTemplate配置的用法,其实在测试过程中并不是一帆风顺,遇到了很多的问题,最主要的就是Mapped Statement ...

  10. PAT甲级——A1013 Battle Over Cities

    It is vitally important to have all the cities connected by highways in a war. If a city is occupied ...