#include<bits/stdc++.h>
#define MAXN 100050
#define MAXM 900000
using namespace std;
struct st
{
int id;
long long dis;
st(int a,long long b)
{
id=a;
dis=b;
}
st(){};
};
struct edge{
bool im;
int id;
long long w;
edge *next;
};
edge *adj[MAXN];
edge edges[MAXM];
int ednum;
inline void add_edge(int a,int b,long long w,bool im){
edge *tmp=&edges[ednum++];
tmp->id=b;
tmp->w=w;
tmp->im=im;
tmp->next=adj[a];
adj[a]=tmp;
}
bool operator < (const st &a,const st &b){
return a.dis>b.dis;
}
long long dis[MAXN];
bool used[MAXN];
void dfss(int num)
{
for(int i=;i<=MAXN;i++){
dis[i]=;
}
priority_queue<st>q;
st tmp;
dis[]=;
q.push(st(,));
while(!q.empty())
{
tmp=q.top();
q.pop();
if(dis[tmp.id]<tmp.dis)continue;
for(edge *p=adj[tmp.id];p;p=p->next)
{
if(dis[p->id]==p->w+dis[tmp.id]){
if(p->im==)used[p->id]=;
}
if(dis[p->id]>p->w+dis[tmp.id])
{
if(p->im)used[p->id]=;
else used[p->id]=;
dis[p->id]=p->w+dis[tmp.id];
q.push(st(p->id,dis[p->id]));
}
}
}
}
int main()
{
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=m;i++){
int u,v;
long long w;
scanf("%d%d%I64d",&u,&v,&w);
add_edge(u,v,w,);
add_edge(v,u,w,);
}
for(int i=;i<=k;i++){
int v;
long long w;
scanf("%d%I64d",&v,&w);
add_edge(,v,w,);
add_edge(v,,w,);
}
dfss();
int ans=;
for(int i=;i<=n;i++){
ans+=used[i];
}
cout << k-ans << endl;
}

Codeforces 450D Jzzhu and Cities [heap优化dij]的更多相关文章

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

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

  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 449B] Jzzhu and Cities

    [题目链接] https://codeforces.com/contest/449/problem/B [算法] 最短路 时间复杂度 : O(N ^ 2) [代码] #include<bits/ ...

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

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

  5. Codeforces 449 B. Jzzhu and Cities

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

  6. CodeForces 450B Jzzhu and Sequences (矩阵优化)

    CodeForces 450B Jzzhu and Sequences (矩阵优化) Description Jzzhu has invented a kind of sequences, they ...

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

  8. CF449B Jzzhu and Cities (最短路)

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

  9. [CF1209F]Koala and Notebook_堆优化dij

    Koala and Notebook 题目链接:https://codeforces.com/contest/1209/problem/F 数据范围:略. 题解: 开始的时候看错题了....莫名其妙多 ...

随机推荐

  1. 【转】object标签和embed标签

    我们现在大部分人做网页,都是直接用DW插入flash,而且DW也是所见即所得,直接生成了相应的flash显示代码.可是我们又有多少人了解这些直接由DW生成的代码呢?其实我接触flash player标 ...

  2. N天前涨停过的票

    zd(0,300,10)B2:=REF(C,1)*1.1-C;B3:BARSLAST(B2<0.01)=ZD01;{n天前涨停股票}

  3. python中时间日期格式化符号

    python中时间日期格式化符号: import time print(time.strftime('%Y%H%M%S', time.localtime())) 运行结果: 2016092308 %y ...

  4. The launch will only sync the application package on the device!

    在开始学习Android的开发时,有时候可能刚写完一个布局文件,就急忙忙的运行程序,此时会毫不留情的在控制台报错:No Launcher activity found! The launch will ...

  5. MockMultipartFile

    org.springframework.mock.webClass MockMultipartFile java.lang.Object org.springframework.mock.web.Mo ...

  6. (转)textarea去掉右侧滚动条,去掉右下角拖拽

    本文转载自:http://blog.csdn.net/cctv_end/article/details/7946188 代码:  <TEXTAREA   style= "overflo ...

  7. ASP.net中网站访问量统计方法代码(在线人数,本月访问,本日访问,访问流量,累计访问)

    一.建立一个数据表IPStat用于存放用户信息 我在IPStat表中存放的用户信息只包括登录用户的IP(IP_Address),IP来源(IP_Src)和登录时间 (IP_DateTime),些表的信 ...

  8. Python 模块学习:re模块

    今天学习了Python中有关正则表达式的知识.关于正则表达式的语法,不作过多解释,网上有许多学习的资料.这里主要介绍Python中常用的正则表达式处理函数. 方法/属性 作用 match() 决定 R ...

  9. (WPF, MVVM) Slider Binding.

    对于Button的Command的绑定可以通过实现ICommand接口来进行,但是Slider并没有Command属性. 另外如果要实现MVVM模式的话,需要将一些Method和Slider的Even ...

  10. python3读取文件

    #coding:utf-8 rfile = open('test.txt','r') str=[] for x in rfile: str = x.split(',') for x in str: p ...