[题目链接]

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. [Python3网络爬虫开发实战] 1.4.2-MongoDB安装

    MongoDB是由C++语言编写的非关系型数据库,是一个基于分布式文件存储的开源数据库系统,其内容存储形式类似JSON对象,它的字段值可以包含其他文档.数组及文档数组,非常灵活. MongoDB支持多 ...

  2. Java 读取linux上的文件

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

  3. AD采集精度中的LSB

    测量范围+5V, 精度10位,LSB=0.0048 精度16位,LSB=0.000076951 测量范围+-5V, 精度10位,LSB=0.009765625,大约为0.01 精度16位,LSB=0. ...

  4. JDBC--JAVA数据库连接相关

    JDBC API提供了以下接口和类: DriverManager: 这个类管理数据库驱动程序的列表.确定内容是否符合从Java应用程序使用的通信子协议正确的数据库驱动程序的连接请求.识别JDBC在一定 ...

  5. 【转】Java IO流 overview

    Java流操作有关的类或接口: Java流类图结构: 流的概念和作用 流是一组有顺序的,有起点和终点的字节集合,是对数据传输的总称或抽象.即数据在两设备间的传输称为流,流的本质是数据传输,根据数据传输 ...

  6. Python模块:time、datetime、random、os、sys、optparse

    time模块的方法: 时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量. struct_time时间元组,共有九个元素组.如下图: time.localtime([secs]): ...

  7. codevs4437 YJQ Arranges Sequences

    题目描述 Description 神犇YJQ有两个长度均为n的数列A和B,并且A是一个单调不增的数列.他认为这两个数列的优美度为.有一天YJQ很无聊,他把Bi进行重新排列,得到了许多不同的优美度.他想 ...

  8. poj——2367  Genealogical tree

    Genealogical tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6025   Accepted: 3969 ...

  9. Spring MVC中的拦截器/过滤器HandlerInterceptorAdapter的使用

    一般情况下,对来自浏览器的请求的拦截,是利用Filter实现的 而在Spring中,基于Filter这种方式可以实现Bean预处理.后处理. 比如注入FilterRegistrationBean,然后 ...

  10. Ubuntu 16.04出现chmod: 无效模式:"a"的问题解决

    命令: chmod a+x file1 提示:注意文件的类型,如果用在文件夹上是不行的,但是文件确实可以的.