[题目链接]

https://codeforces.com/contest/449/problem/B

[算法]

最短路

时间复杂度 : O(N ^ 2)

[代码]

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + ;
const int INF = 2e9; int n , m , k;
int mark[MAXN];
long long dist[MAXN];
bool inq[MAXN];
vector< pair<int,int> > G[MAXN]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} int main()
{ read(n); read(m); read(k);
for (int i = ; i <= m; i++)
{
int u , v , w;
read(u); read(v); read(w);
G[u].push_back(make_pair(v,w));
G[v].push_back(make_pair(u,w));
}
queue< int > q;
for (int i = ; i <= n; i++)
{
dist[i] = INF;
mark[i] = ;
inq[i] = false;
}
dist[] = ;
q.push();
inq[] = true;
for (int i = ; i <= k; i++)
{
int u , w;
read(u); read(w);
mark[u] = ;
if (w < dist[u])
{
dist[u] = w;
if (!inq[u])
{
inq[u] = true;
q.push(u);
}
}
}
while (!q.empty())
{
int u = q.front();
q.pop();
inq[u] = false;
for (unsigned i = ; i < G[u].size(); i++)
{
int v = G[u][i].first , w = G[u][i].second;
if (dist[u] + w <= dist[v] && mark[v]) mark[v] = ;
if (dist[u] + w < dist[v])
{
dist[v] = dist[u] + w;
if (!inq[v])
{
inq[v] = true;
q.push(v);
}
}
}
}
for (int i = ; i <= n; i++) k -= mark[i];
printf("%d\n",k); return ; }

[Codeforces 449B] Jzzhu and Cities的更多相关文章

  1. codeforces 449B Jzzhu and Cities (Dij+堆优化)

    输入一个无向图<V,E>    V<=1e5, E<=3e5 现在另外给k条边(u=1,v=s[k],w=y[k]) 问在不影响从结点1出发到所有结点的最短路的前提下,最多可以 ...

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

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

  3. Codeforces 450D Jzzhu and Cities [heap优化dij]

    #include<bits/stdc++.h> #define MAXN 100050 #define MAXM 900000 using namespace std; struct st ...

  4. Codeforces449A Jzzhu and Chocolate && 449B Jzzhu and Cities

    CF挂0了,简直碉堡了.两道题都是正确的思路但是写残了.写个解题报告记录一下心路历程. A题问的是 一个n*m的方块的矩形上切k刀,最小的那一块最大可以是多少.不难发现如果纵向切k1刀,横向切k2刀, ...

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

  6. Codeforces 449 B. Jzzhu and Cities

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

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

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

  8. CF449B Jzzhu and Cities (最短路)

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

  9. Codeforces 449B

    题目链接 B. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

随机推荐

  1. Bash的循环结构(for和while)

    在bash有三中类型的循环结构表达方法:for,while,until.这里介绍常用的两种:for和while. for bash的for循环表达式和python的for循环表达式风格很像: for ...

  2. Java 读取linux上的文件

    今天遇到一个问题,在Windows环境上开发,测试环境和正式环境服务器都是linux: 一个导出表格的功能,在本地没问题,发布到linux服务器就报找不到文件问题,但是模板文件已经在linux下了.刚 ...

  3. mysql查询排名

    student_work表 student_info表 sql语句:按grade从高到低排名 结果:

  4. Ajax的特点

    [传统提交方式] 客户端提交请求后,服务器会找到相应的资源进行执行.并将执行结果重新发送给客户端.客户端接收到服务器端的响应会进行重新解释并显示.此时的页面是一个全新的页面. [Ajax提交] 客户端 ...

  5. Leetcode 139.单词拆分

    单词拆分 给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词. 说明: 拆分时可以重复使用字典中的单词. 你可以假设字典 ...

  6. 7-26 Windows消息队列(25 分)(堆排序)

    7-26 Windows消息队列(25 分) 消息队列是Windows系统的基础.对于每个进程,系统维护一个消息队列.如果在进程中有特定事件发生,如点击鼠标.文字改变等,系统将把这个消息加到队列当中. ...

  7. 树剖 lca

    GeneralLiu  橙边为轻边 红边为重边 绿数为每个点的 top 橙数为每个点的编号 步骤 1 先预处理 每个点的 deep深度  size子树大小  dad父节点 2 再预处理 每个点的 to ...

  8. 莫比乌斯反演套路三、四--BZOJ2154: Crash的数字表格 && BZOJ2693: jzptab

    t<=1e4个询问每次问n,m<=1e7,$\sum_{1\leqslant x \leqslant n,1 \leqslant y\leqslant m}lcm(x,y)$. 首先题目要 ...

  9. Bad Hair Day-POJ3250(简单的入栈出栈)

    Description Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow ...

  10. gradle 安装及设置本地仓库地址

    进入地址:http://services.gradle.org/ 下载-bin.zip 解压到自己指定的目录. 配置环境变量 GRADLE_HOME  gradle的根目录. 在path 中 添加 % ...