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 m roads 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.

Examples
input

Copy
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

Copy
2
input

Copy
2 2 3
1 2 2
2 1 3
2 1
2 2
2 3
output

Copy
2

一次spfa
考虑对每个点,每次被更新时,有两种情况,铁路和公路,被铁路更新标记为1(被认为不能删),被公路更新就标记回0.
另一方面,当dis[v]==dis[u]+w时,如果已被标记为1,那还需要重新标记
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
return max(max(a, b), max(c, d));
}
#define scanf1(x) scanf("%d", &x)
#define scanf2(x, y) scanf("%d%d", &x, &y)
#define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int N =1e6;
const int M=;
// name*******************************
struct edge
{
int to,nxt;
ll w;
} e[N];
int tot=;
int fst[N];
ll dis[N];
int ins[N];
int vis[N];
int pos[N];
priority_queue<int>que;
int sum=;
int n,m,k;
// function******************************
void add(int u,int v,int w)
{
e[++tot].to=v;
e[tot].nxt=fst[u];
fst[u]=tot;
e[tot].w=w;
}
void spfa()
{
For(i,,n)dis[i]=INF;
que.push();
ins[]=;
dis[]=;
while(!que.empty())
{
int u=que.top();
que.pop();
ins[u]=;
for(int p=fst[u]; p; p=e[p].nxt)
{
int v=e[p].to;
ll w=e[p].w;
if(dis[v]==dis[u]+w&&pos[v])
pos[v]=vis[p];
if(dis[v]>dis[u]+w)
{
dis[v]=dis[u]+w;
pos[v]=vis[p];
if(!ins[v])
{
ins[v]=;
que.push(v);
}
}
}
}
} //***************************************
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
// freopen("test.txt", "r", stdin);
// freopen("outout.txt","w",stdout);
scanf("%d%d%d",&n,&m,&k);
For(i,,m)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
For(i,,k)
{
int x,y;
scanf("%d%d",&x,&y);
add(,x,y);
vis[tot]=;
}
spfa();
For(i,,n)
sum+=pos[i];
cout<<k-sum; return ;
}

D. Jzzhu and Cities的更多相关文章

  1. CF449B Jzzhu and Cities (最短路)

    CF449B CF450D http://codeforces.com/contest/450/problem/D http://codeforces.com/contest/449/problem/ ...

  2. Codeforces Round #257 (Div. 2) D题:Jzzhu and Cities 删特殊边的最短路

    D. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces 449 B. Jzzhu and Cities

    堆优化dijkstra,假设哪条铁路能够被更新,就把相应铁路删除. B. Jzzhu and Cities time limit per test 2 seconds memory limit per ...

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

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

  5. CF449B Jzzhu and Cities 迪杰斯特拉最短路算法

    CF449B Jzzhu and Cities 其实这一道题并不是很难,只是一个最短路而已,请继续看我的题解吧~(^▽^) AC代码: #include<bits/stdc++.h> #d ...

  6. Codeforces 450D:Jzzhu and Cities(最短路,dijkstra)

    D. Jzzhu and Cities time limit per test: 2 seconds memory limit per test: 256 megabytes input: stand ...

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

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

  8. Codeforces Round #257(Div.2) D Jzzhu and Cities --SPFA

    题意:n个城市,中间有m条道路(双向),再给出k条铁路,铁路直接从点1到点v,现在要拆掉一些铁路,在保证不影响每个点的最短距离(距离1)不变的情况下,问最多能删除多少条铁路 分析:先求一次最短路,铁路 ...

  9. Codeforces 450D Jzzhu and Cities [heap优化dij]

    #include<bits/stdc++.h> #define MAXN 100050 #define MAXM 900000 using namespace std; struct st ...

随机推荐

  1. Code Signal_练习题_differentSymbolsNaive

    Given a string, find the number of different characters in it. Example For s = "cabca", th ...

  2. idea配置热部署

    第一步:添加依赖使用spring-boot-devtools提供的开发者工具spring-boot项目中引入如下依赖 <dependency><groupId>org.spri ...

  3. html 手机web超出屏幕宽度的内容不换行,并产生横向滚动条

     html 手机web超出屏幕宽度的内容不换行,并产生横向滚动条 white-space: nowrap;overflow-x: scroll;    

  4. 深入解读《Gartner2017年商业智能和分析平台魔力象限报告》

    文 | 帆软数据应用研究院 船长 2017年2月16日,Gartner发布了2017年BI商业智能和分析平台魔力象限报告,笔者这里进行一些解读,帮助大家更好了解市场状况和趋势. 一.几家欢笑几家愁 和 ...

  5. ActiveReports 报表应用教程 (16)---报表导出

    葡萄城ActiveReports报表支持多种格式的报表导出,包括PDF.Excel.Word.RTF.HTML.Text.TIFF以及其它图片格式,用户可以将它们应用到Windows Forms.We ...

  6. android中checkbox自定义样式

    1.首先res/drawable中定义checkbox_style.xml样式: <?xml version="1.0" encoding="utf-8" ...

  7. Python笔记(十三):urllib模块

    (一)      URL地址 URL地址组件 URL组件 说明 scheme 网络协议或下载方案 net_loc 服务器所在地(也许含有用户信息) path 使用(/)分割的文件或CGI应用的路径 p ...

  8. C# socket 发送图片和文件

    先说服务端:界面:如图: 界面设计源码 namespace SocketJPGToTxt { partial class Form1 { /// <summary> /// 必需的设计器变 ...

  9. CSS| font property

    字體屬性 常用的CSS字体名称 宋体 SimSun 黑体 SimHei 微软雅黑 Microsoft YaHei 微软正黑体 Microsoft JhengHei 新宋体 NSimSun 新细明体 P ...

  10. 根据模板导出Excel报表并复制模板生成多个Sheet页

    因为最近用报表导出比较多,所有就提成了一个工具类,本工具类使用的场景为  根据提供的模板来导出Excel报表 并且可根据提供的模板Sheet页进行复制 从而实现多个Sheet页的需求, 使用本工具类时 ...