[Codeforces 449B] Jzzhu and Cities
[题目链接]
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的更多相关文章
- codeforces 449B Jzzhu and Cities (Dij+堆优化)
输入一个无向图<V,E> V<=1e5, E<=3e5 现在另外给k条边(u=1,v=s[k],w=y[k]) 问在不影响从结点1出发到所有结点的最短路的前提下,最多可以 ...
- Codeforces C. Jzzhu and Cities(dijkstra最短路)
题目描述: Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces 450D Jzzhu and Cities [heap优化dij]
#include<bits/stdc++.h> #define MAXN 100050 #define MAXM 900000 using namespace std; struct st ...
- Codeforces449A Jzzhu and Chocolate && 449B Jzzhu and Cities
CF挂0了,简直碉堡了.两道题都是正确的思路但是写残了.写个解题报告记录一下心路历程. A题问的是 一个n*m的方块的矩形上切k刀,最小的那一块最大可以是多少.不难发现如果纵向切k1刀,横向切k2刀, ...
- 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 ...
- Codeforces 449 B. Jzzhu and Cities
堆优化dijkstra,假设哪条铁路能够被更新,就把相应铁路删除. B. Jzzhu and Cities time limit per test 2 seconds memory limit per ...
- Codeforces 450D:Jzzhu and Cities(最短路,dijkstra)
D. Jzzhu and Cities time limit per test: 2 seconds memory limit per test: 256 megabytes input: stand ...
- CF449B Jzzhu and Cities (最短路)
CF449B CF450D http://codeforces.com/contest/450/problem/D http://codeforces.com/contest/449/problem/ ...
- Codeforces 449B
题目链接 B. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
随机推荐
- Go:struct
一.使用方式 方式3和方式4返回的是:结构体指针,编译器底层对 p.Name 做了转化 *(p).Name,方便程序员使用. type Person struct { Name string Age ...
- c++基础_回文数
#include <iostream> using namespace std; int main(){ ;i<;i++){ ; int n=i;//暂存该四位数来计算 ,以防改变i ...
- Python数据类型之数字类型
整数 在Python中,整数可以执行 加(+)减(-)乘(*)除(/) 运算. 1 + 2 3 - 2 2 * 3 3 / 2 # 1.5 在控制台,Python直接返回运算结果. Python中也可 ...
- MySQL简单查询和单表查询
MySQL记录操作 概览 MySQL数据操作: DML 在MySQL管理软件中,可以通过SQL语句中的DML语言来实现数据的操作,包括 使用INSERT实现数据的插入 UPDATE实现数据的更新 使用 ...
- 88-On Balance Volume 能量潮指标.(2015.7.4)
On Balance Volume 能量潮指标 ~计算方法: 如果当天的收盘价高于昨天的话,那么:OBV(i) = OBV(i-1)+VOLUME(i) 如果当天的收盘价低于昨天的话,那么:OBV(i ...
- java ssm框架 mapper文件里的#符号和$符号的区别
Java SSM框架里面,Mapper.xml文件 (一)#符号生成的sql语句是作为传参的 <!-- 获得数据列表(包括课程相关信息) --> <select id="G ...
- CSS实现折叠面板
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- SQLAlchemy(1):单表操作
SQLAlchemy 是一个 ORM框架:类对应表,类中的字段对应表中的列,类的对象对应表的一条记录:作用:帮助我们使用类和对象快速实现数据库操作操作数据库的方式: 1. 原生SQL - pymysq ...
- 选择器的使用(first-child和last-child选择器)
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta ...
- Ubuntu 16.04通过Magent搭建Memcached集群(转)
一.下载Magent 官网:https://code.google.com/archive/p/memagent/downloads 离线版本:(链接: https://pan.baidu.com/s ...