[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 ...
随机推荐
- 性能测试培训day2
上节课 性能测试,多线程.协议.场景 实施:1,脚本开发 运行 排错(看回放,然后view-test_results,看业务) 参数化.关联.检查点.事务.思考时间.集合点 参数化:不做参数化的话, ...
- 树莓派 -- 输入设备驱动 (key)
输入设备(如按键,键盘,触摸屏等)是典型的字符设备,其一般工作原理是底层在按键或触摸等动作发生时产生一个中断,然后CPU通过SPI,I2C总线读取键值. 在这些工作中之后中断和读键值是与设备相关的,而 ...
- 关于ie8下disabled属性:字体颜色问题
在ie8下,input/textarea输入框如果使用disabled属性,字体的颜色会变灰,这时我们可以使用另一种方法实现它. 不使用disabled,用readonly代替: input[read ...
- CSS+DIV命名
原地址:http://www.cnblogs.com/hylaz/archive/2012/10/27/2742743.html#2521377 页头:header 登录条:loginBar 标志:l ...
- Auto-Encoders实战
目录 Outline Auto-Encoder 创建编解码器 训练 Outline Auto-Encoder Variational Auto-Encoders Auto-Encoder 创建编解码器 ...
- LeetCode(50) Pow(x,n)
题目 Implement pow(x, n). Show Tags Show Similar Problems 分析 一个不利用标准幂次函数的,求幂算法实现. 参考了一个很好的解析博客:Pow(x,n ...
- 贪心 Radar Installation (求最少探测雷达)
Description Assume the coasting is an infinite straight line. Land is in one side of coasting, sea i ...
- HttpURLConnection绕过HTTPS的SSL验证
(这个jdk环境需要是1.8,以上). 直接在类里面加一个static代码块 static { try { trustAllHttpsCertificates(); HttpsURLConnectio ...
- SQlServer中的MD5加密
SELECT sys.fn_varbintohexstr(HASHBYTES('MD5', '我'));
- 编程数学(A-1)-(B-1)-一个数的负次方怎么算
一个数的负几次方就是这个数的几次方的倒数.当这个数是正整数时,也就是说一个数的负n次方就是这个数的n次方分之一.例如: 2的-2次方=2的2次方分之1=4分之13的-2次方=3的2次方分之1=9分之1 ...