[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 ...
随机推荐
- Linux CentOS7.5静默安装Oracle11gR2
网上有很多安装教程,但大多不够完整,参照了一些教程,实测安装成功,整理出来分享给大家! 一.官方最低要求配置 内存:1G(官方最低要求1G) 硬盘:40G(企业版安装所需4.29G和1.7G数据文件) ...
- 集训第六周 数学概念与方法 概率 F题
Submit Status Description Sometimes some mathematical results are hard to believe. One of the common ...
- 【04】< meta > 元素
< meta > 元素 概要 标签提供关于HTML文档的元数据.元数据不会显示在页面上,但是对于机器是可读的.它可用于浏览器(如何显示内容或重新加载页面),搜索引擎(关键词),或其他 we ...
- c语音 dll断点调试方法
转自:https://blog.csdn.net/qingzai_/article/details/45348613 dll调试方法: 1.把最新生成的dll和pdb放到 启动这个dll 的进程目录下 ...
- CodeForcesGym 100517H Hentium Scheduling
Hentium Scheduling Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForc ...
- CMM
CMM CMM的基本概念 CMM(Capability Maturity Model for Software) 它是对于软件组织在定义,实施,度量,控制和改善其软件过程的实践中各个发展阶段的描述.其 ...
- Linux备份-删除指定日期内文件
#!/usr/bin/env bash source /etc/profile echo " *************** start filter *************** &q ...
- HDU 5024
题目大意: 在2个图上显示为'.'的位置建两座房间,保证这两间房子中间只转一个90度的弯,可以斜着走,问能建成房子的最远的路程长度为多少 暴力枚举 因为有8个方向,但横竖走和斜着走是不会产生90度角的 ...
- hdu 5029树链剖分
/* 解:标记区间端点,按深度标记上+下-. 然后用线段树维护求出最小的,再将它映射回来 */ #pragma comment(linker, "/STACK:102400000,10240 ...
- CentOS7下搭建postfix邮箱服务器并实现extmail的web访问
http://blog.51cto.com/zero01/2064693 https://blog.csdn.net/a5nan/article/details/52510887