Codeforces 449B
B. Jzzhu and Citiestime limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
InputThe 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 ≤ n; ui ≠ 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.
OutputOutput a single integer representing the maximum number of the train routes which can be closed.
Sample test(s)input5 5 3
1 2 1
2 3 2
1 3 3
3 4 4
1 5 5
3 5
4 5
5 5output2input2 2 3
1 2 2
2 1 3
2 1
2 2
2 3output2
/*************************************************************************
> 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的更多相关文章
- [Codeforces 449B] Jzzhu and Cities
[题目链接] https://codeforces.com/contest/449/problem/B [算法] 最短路 时间复杂度 : O(N ^ 2) [代码] #include<bits/ ...
- codeforces 449B Jzzhu and Cities (Dij+堆优化)
输入一个无向图<V,E> V<=1e5, E<=3e5 现在另外给k条边(u=1,v=s[k],w=y[k]) 问在不影响从结点1出发到所有结点的最短路的前提下,最多可以 ...
- Codeforces Round #257 (Div. 1) (Codeforces 449B)
题意:给力一张无向图,有一些边是正常道路,有一些边是铁路,问最多能删除几条铁路使得所有点到首都(编号为1)的最短路长度不变. 思路:求不能删除的铁路数,总数减掉就是答案.先求出首都到所有点的最短路,求 ...
- CodeForces - 449B 最短路(迪杰斯特拉+堆优化)判断最短路路径数
题意: 给出n个点m条公路k条铁路. 接下来m行 u v w //u->v 距离w 然后k行 v w //1->v 距离w 如果修建了铁路并不影响两点的最短距离, ...
- Codeforces C. Jzzhu and Cities(dijkstra最短路)
题目描述: Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 专题:CF图论杂题
题目是来自HZW的博客(构造题我是各种不会...) Solved 1 / 1 A CodeForces 500A New Year Transportation Solved 1 / 1 B Code ...
- CCPC-Wannafly Summer Camp 2019 Day1
A - Jzzhu and Cities CodeForces - 449B 题意:n座城市,m条路,k条铁路啥的吧,然后要求最多能删多少条铁路保持1到$n$的最短路不变. 思路:因为铁路是从1出发的 ...
- Aizu 2249 & cf 449B
Aizu 2249 & cf 449B 1.Aizu - 2249 选的边肯定是最短路上的. 如果一个点有多个入度,取价值最小的. #include<bits/stdc++.h> ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- javaSpring学习总结day_01
本文章用于总结自己学习知识,有不足或错误之处清谅解. bean.xml 文件的读取方式: ClassPathXmlApplicationContext: 它是只能加载类路径下的配置文件 推荐 1.加载 ...
- IntelliJ IDEA community 安装教程
jetbrains官网下载 IntelliJ IDEA安装包 https://www.jetbrains.com/idea/download/#section=windows 此处选择社区版的zip文 ...
- Image 转换成 Icon
/// <summary> /// Converts an image into an icon. /// </summary> /// <param name=&quo ...
- kafka一些问题点的分析
kakfka架构图: 理解kafka需要理解三个问题. 1.producer,broker,consumer,ZK的工作模式. broker,ZK是作为一个后台服务,而producer和consume ...
- HLog工作原理
- C/C++基础:main函数的参数argc和argv
转载: https://blog.csdn.net/Eastmount/article/details/20413773 一.main()函数参数 通常我们在写主函数时都是void main()或in ...
- tcpdump 抓包
简介 用简单的话来定义tcpdump,就是:dump the traffic on a network,根据使用者的定义对网络上的数据包进行截获的包分析工具. tcpdump可以将网络中传送的数据包的 ...
- [Hdu-5155] Harry And Magic Box[思维题+容斥,计数Dp]
Online Judge:Hdu5155 Label:思维题+容斥,计数Dp 题面: 题目描述 给定一个大小为\(N*M\)的神奇盒子,里面每行每列都至少有一个钻石,问可行的排列方案数.由于答案较大, ...
- bzoj1003物流运输 最短路+DP
bzoj1003物流运输 题目描述 物流公司要把一批货物从码头A运到码头B.由于货物量比较大,需要n天才能运完.货物运输过程中一般要转停好几个码头.物流公司通常会设计一条固定的运输路线,以便对整个运输 ...
- Tuxera ntfs软件如何删除干净
sudo /Library/Filesystems/fusefs_txantfs.fs/Contents/Resources/Support/uninstall-package.sh