题目链接

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. 2006-2007 ACM-ICPC | POJ3380 POJ3384 POJ3385 水题题解

    // CF比赛链接:http://codeforces.com/gym/101650 // POJ链接:http://poj.org/searchproblem?field=source&ke ...

  2. 2018-12-18-WPF-一个空的-WPF-程序有多少个窗口

    title author date CreateTime categories WPF 一个空的 WPF 程序有多少个窗口 lindexi 2018-12-18 21:16:40 +0800 2018 ...

  3. 解决element-ui表头错位的问题

    经过测试得出: 使用element-ui的表格,并在table中设置固定height会出现表头错位的现象(不知道是什么bug) 解决方案: 将height改为max-height,设置固定高度为最大高 ...

  4. 90 k数和 II

    原题网址:https://www.lintcode.com/problem/k-sum-ii/description 描述 Given n unique integers, number k (1&l ...

  5. JEECMS自定义标签

    查看JEECMS的源代码发现开发者版本还没有类似现成的统计标签,一种解决的办法是使用现有的JEECMS标签,像这样Struts( [@cms_content_list channel=id]${tag ...

  6. Maven实战06_坐标和邮件服务模块

    1:何为Maven坐标 为了能够自动化地解析任何一个Java构件,Maven就必须要将其唯一标识,这就是依赖管理的底层基础--坐标. 学过数学的人都知道平面直角坐标系,x,y分别为其横,纵坐标,将会在 ...

  7. webServices学习三(概念详解)

    WebService通过HTTP协议完成远程调用: (深入分析) WebService只采用HTTP POST方式传输数据,不使用GET方式; -- 握手,WSDL-get, 普通http post的 ...

  8. 3.appium定位方法

    1.使用id定位: driver.find_element_by_id('id的名称').click() 2.使用className定位: driver.find_element_by_class_n ...

  9. Data Lake Analytics,大数据的ETL神器!

    0. Data Lake Analytics(简称DLA)介绍 数据湖(Data Lake)是时下大数据行业热门的概念:https://en.wikipedia.org/wiki/Data_lake. ...

  10. 2019阿里云开年Hi购季满返活动火热报名中!

    摘要: 在每年开年的这个大幅度优惠促销月,怎样才能花最少的钱配置最特惠的云服务?请看本文! 2019阿里云云上采购季活动已经于2月25日正式开启,从已开放的活动页面来看,活动分为三个阶段: 2月25日 ...