#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. 【转】Win7注册表的使用(更新中)

    一.注册表的存储结构和数据类型 1.基本概念: Windows 7的注册表主要由“键”和“键值”构成,称HKEY为根键(RootKey),SubKey为子键. 键(Key):“位于左侧窗格如同文件夹图 ...

  2. Oracle无法启动,ORA-01034、ORA-01078

    因为调整32位系统的SGA区大小时不慎,超出可用内存,造成Oracle实例无法启动,报出ORA-01034.ORA-01078等错误.如下图 sqlplus /nolog SQL> conn / ...

  3. ajax用户名案例(重点)

      要求:失去焦点时如下效果 主页代码 <body> 用户名:<input type="text" id="a" /><div i ...

  4. css布局实践心得总结

    一.摘要: 今天在写一个页面,对css中的BFC(块级格式化范围)有了一点体会,今天把遇到的问题和解决方案总结下来,额外还总结一下强大的负外边距的使用心得. 二.总结:

  5. HackerRank "Morgan and a String"

    I saw the same sub-problem in LeetCode, and there exists a O(n) neat greedy solution: for _ in range ...

  6. HackerRank "No Prefix Set"

    Typical Trie usage. But please note that it could be any order of input strings. #include <algori ...

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

    希望通过博客园持续的更新,分享和记录Python基础知识到高级应用的点点滴滴! 第五波:第1章  基础知识 [总览]  介绍如何得到所需的软件,然后讲一点点算法及其主要的组成.学习变量variable ...

  8. FIR系统的递归与非递归实现

    首先,因为FIR的脉冲响应是有限长,所以总是可以非递归实现的: 其次,也可以用递归系统来实现它. 以滑动平均做例子,最直观的想法就是,每次来一个新的值,丢掉最老的,加上最新的: y[n]=y[n-1] ...

  9. hibernate.cfg.xml讲解

    <session-factory> <!-- 配置数据库连接信息 --> <!-- 数据库驱动 --> <property name="connec ...

  10. 创建immutable类

    不可变对象(immutable objects) 那么什么是immutable objects?什么又是mutable Objects呢? immutable Objects就是那些一旦被创建,它们的 ...