#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. RMAN备份与恢复之不完全恢复

    要点:对于RMAN的不完全恢复,有如下步骤: 1)加载数据到mount状态(建议恢复前先做备份) 2)为高并发分配多个通道 3)还原所有(所需)的数据文件 4)使用until time,until s ...

  2. java生成随机字符串uuid

    GUID是一个128位长的数字,一般用16进制表示.算法的核心思想是结合机器的网卡.当地时间.一个随即数来生成GUID.从理论上讲,如果一台机器每秒产生10000000个GUID,则可以保证(概率意义 ...

  3. DW(六):polybase访问Azure Blob Storage

    目录: 连接hadoop配置语法 配置hadoop连接 Pushdown配置 Create external tables for Azure blob storage 连接hadoop配置语法: g ...

  4. 【Spring学习笔记-0】Spring开发所需要的核心jar包

    spring开发所需要的核心jar 1. libs目录下的核心jar包: 2. common-logging-xxx.jar 来自为知笔记(Wiz) 附件列表

  5. 使用 Override 和 New 关键字进行版本控制

    使用 Override 和 New 关键字进行版本控制 C# 语言经过专门设计,以便不同库中的基类与派生类之间的版本控制可以不断向前发展,同时保持向后兼容. 这具有多方面的意义.例如,这意味着在基类中 ...

  6. Redis内存使用优化与存储(转)

    Redis常用数据类型 Redis最为常用的数据类型主要有以下五种: String Hash List Set Sorted set 在具体描述这几种数据类型之前,我们先通过一张图了解下Redis内部 ...

  7. C#数字千分位问题

    1.C#中用最简单的方法把数字(不含小数)转换为千分位格式:     如1234567变成1,234,567 方法:1234567.ToString("###,###")   或  ...

  8. hibernate 组件(Component)映射

    1.类Teacher public class Teacher { private int id; private String name; private String sex; private A ...

  9. Spark工程开发前台技术实现与后台函数调用

    Spark是一个通用的大规模数据快速处理引擎.可以简单理解为Spark就是一个大数据分布式处理框架.基于内存计算的Spark的计算速度要比Hadoop的MapReduce快上50倍以上,基于磁盘的计算 ...

  10. DBA_Oracle Erp R12安装虚拟机镜像IP修正(案例)

    2014-07-12 Created By BaoXinjian