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.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- topology进程结束会不会关闭数据库连接
测试环境:redhat,oracle 11.2.0.3.0 测试目标:当java进程关闭之后,进程的数据库连接会不会被释放,何时被释放 实验证明:在运行topology前,执行 select coun ...
- An invalid property 'jdbcType ' was found in mapping
大概2种原因: 1 放进去的类型与字段的类型不匹配 2 比较变态,xml中=两边不能有空格! 错误示例如下: #{plat,jdbcType = INTEGER}, 去掉空格后: #{plat,jd ...
- python学习笔记4.1_检测和过滤异常值
1.查看数据分布data.describe() 2.找出某列中符合筛选条件的值 3.找出符合筛选条件的行 4.用np.sign(data)*3设置绝对值的标准 data[np.abs(data)> ...
- 在AlexNet中LRN 局部响应归一化的理
在AlexNet中LRN 局部响应归一化的理 一.LRN技术介绍: Local Response Normalization(LRN)技术主要是深度学习训练时的一种提高准确度的技术方法.其中caffe ...
- win8 风格框架
http://metroui.org.ua/挺不错 bootstrap 系列的.
- webapp中<meta>与css代码部署
1.页面头部标签申明 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" id="te ...
- 廖雪峰Java11多线程编程-1线程的概念-1多线程简介
多任务 现代操作系统(windows,MacOS,Linux)都可以执行多任务: 多任务就是同时运行多个任务,例如同时开启钉钉.百度网盘.火狐.谷歌.ps等 操作系统执行多任务就是让多个任务交替执行, ...
- html常用标签6-表单标签
1.表单的初始化标签 <form action="#" method="get"><!--表单的开始--> </form> ...
- UVA11722 Jonining with Friend
Joining with Friend You are going from Dhaka to Chittagong by train and you came to know one of your ...
- Zigbee安全入门(一)—— 技术介绍和安全策略
么是Zigbee? Zigbee说白了就是类似wifi.蓝牙的一种交换数据的方式,学术点说就是低成本.用于低功耗嵌入式设备(无线电系统),用以促进机器与机器之间高效且有效通信(通常相距10-100米) ...