#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. TKinter的常用组件

    python提供了多个图形开发界面的库,几个常用Python GUI库如下: Tkinter: Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口.T ...

  2. 转(linux shell)(2)

      http://oldboy.blog.51cto.com/2561410/1665163 1.按单词出现频率降序排序! 2.按字母出现频率降序排序! the squid project provi ...

  3. LinkedHashMap和HashMap区别

    import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.uti ...

  4. 运行ASP程序报错

    错误提示: An error occurred on the server when processing the URL. Please contact the system administrat ...

  5. jquery.find()

    http://www.365mini.com/page/jquery-find.htm

  6. Jenkins: 基础篇(环境配置)

    自动化领域比较有影响力的开源框架jenkins,确实比较强大,易用.很多公司将其用来做持续即成CI(continuous integration).为了拓展和强化自己的软件设计生态系统,也将很久前使用 ...

  7. Python基础(二) —— 字符串、列表、字典等常用操作

    一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. 二.三元运算 result = 值1 if 条件 else 值2 如果条件为真:result = 值1如果条件为 ...

  8. 06 Linux下Shell介绍

    一.概述 每个人在成功登陆Linux后,系统会出现不同的提示符号,例如$,~,#等,然后你就可以开始输入需要的命令.若命令正确,系统就会依据命令的要求来执行,直到注销系统为止,在登陆到注销期间,输入的 ...

  9. 【转】JDBC为什么要使用PreparedStatement而不是Statement

    http://www.importnew.com/5006.html PreparedStatement是用来执行SQL查询语句的API之一,Java提供了 Statement.PreparedSta ...

  10. (C/C++) Interview in English - Basic concepts.

    Question Key words Anwser A assignment operator abstract class It is a class that has one or more pu ...