#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. mysql 修改字符集

    查看mysql数据编码 登录MySQL服务,查看mysql数据库默认的编码 mysql> show variables like 'character%'; +----------------- ...

  2. C# 中如何判断某个字符串是否为空的方法

    C# 中如何判断某个字符串是否为空的方法 分享了三个方法来判断字符串是否为空 引自:http://www.itokit.com/2012/0724/74618.html 1. 三种常用的字符串判空串方 ...

  3. Swift使用Alamofire实现网络请求

    Alamofire是一个用Swift编写的HTTP网络库,由此前热门开源项目AFNetworking的的作者mattt开发,可非常简单地用于异步网络通信. 要获取最新版本的 Alamofire,前往h ...

  4. js实现复选框的全选、全不选、反选

    js中实现复选框的全选,全不选以及反选,分为两种情况: (1)选中“请选择”前面的复选框实现全选,不选中“请选择”前面的复选框实现全不选 <!DOCTYPE html PUBLIC " ...

  5. 阅读layim代码小记,实现可以更改用户签名的方法

    用layim原版的时候发现,用户的签名是不能直接修改的,如下: 其实要改也很简单,查看一下源代码,然后加一个input进去,可是,加完之后是这样的: 没关系,给它一个样式,让它乖乖的“隐藏“起来. / ...

  6. LINQ to SQL语句

    http://kb.cnblogs.com/page/42477/2/ 本系列文章导航 LINQ to SQL语句(1)之Where LINQ to SQL语句(2)之Select/Distinct ...

  7. WPF拖到、移动控件

    只需2个事件和一个point变量即可: Point mouse_offset = , ); void TC_MouseLeftButtonDown(object sender, MouseButton ...

  8. Python基础教程【读书笔记】 - 2016/7/31

    希望通过博客园持续的更新,分享和记录Python基础知识到高级应用的点点滴滴! 第十波:第10章  充电时刻 Python语言的核心非常强大,同时还提供了更多值得一试的工具.Python的标准安装包括 ...

  9. (转)扩展jquery easyui datagrid 之动态绑定列和数据

    本文转载自:http://blog.csdn.net/littlewolf766/article/details/7336550 easyui datagrid 不支持动态加载列,上次使用的方法是自己 ...

  10. Spark on Yarn 架构解析

    . 一.Hadoop Yarn组件介绍: 我们都知道yarn重构根本的思想,是将原有的JobTracker的两个主要功能资源管理器 和 任务调度监控 分离成单独的组件.新的架构使用全局管理所有应用程序 ...