最短路 Codeforces Round #103 (Div. 2) D. Missile Silos
/*
最短路: 不仅扫描边,还要扫描点;点有两种情况,一种刚好在中点,即从u,v都一样,那么最后/2
还有一种是从u,v不一样,两种的距离都是l
模板错了,逗了好久:(
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
using namespace std; const int MAXN = 1e5 + ;
const int INF = 0x3f3f3f3f;
int d[MAXN];
int cnt[MAXN];
bool vis[MAXN];
vector<pair<int, int> > G[MAXN];
int n, m, s, l, ans, ans2; void SPFA(void) {
memset (vis, false, sizeof (vis));
memset (d, INF, sizeof (d)); d[s] = ;
queue<int> Q; Q.push (s);
while (!Q.empty ()) {
int u = Q.front (); Q.pop ();
vis[u] = false;
for (int i=; i<G[u].size (); ++i) {
int v = G[u][i].first; int w = G[u][i].second;
if (d[v] > d[u] + w) {
d[v] = d[u] + w;
if (!vis[v]) {
vis[v] = true; Q.push (v);
}
}
}
}
} int main(void) { //Codeforces Round #103 (Div. 2) D. Missile Silos
//freopen ("spfa.in", "r", stdin); while (scanf ("%d%d%d", &n, &m, &s) == ) {
for (int i=; i<=m; ++i) {
int u, v, w; scanf ("%d%d%d", &u, &v, &w);
G[u].push_back (make_pair (v, w)); G[v].push_back (make_pair (u, w));
}
scanf ("%d", &l); SPFA (); ans = ans2 = ;
for (int i=; i<=n; ++i) {
for (int j=; j<G[i].size (); ++j) {
int u = i, v = G[i][j].first, w = G[i][j].second;
if (d[u] < l && l - d[u] < w) {
if (w - (l-d[u]) + d[v] > l) ans++;
else if (d[u] + d[v] + w == * l) ans2++;
}
}
if (d[i] == l) ans++;
}
printf ("%d\n", ans + ans2 / );
} return ;
}
最短路 Codeforces Round #103 (Div. 2) D. Missile Silos的更多相关文章
- Codeforces Round #103 (Div. 2) D. Missile Silos(spfa + 枚举边)
题目链接:http://codeforces.com/problemset/problem/144/D 思路:首先spfa求出中心点S到其余每个顶点的距离,统计各顶点到中心点的距离为L的点,然后就是要 ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- Codeforces Round #372 (Div. 2)
Codeforces Round #372 (Div. 2) C. Plus and Square Root 题意 一个游戏中,有一个数字\(x\),当前游戏等级为\(k\),有两种操作: '+'按钮 ...
- Codeforces Round #257 (Div. 1)A~C(DIV.2-C~E)题解
今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and ...
- Codeforces Round #485 (Div. 2)
Codeforces Round #485 (Div. 2) https://codeforces.com/contest/987 A #include<bits/stdc++.h> us ...
- Codeforces Round #556 (Div. 1)
Codeforces Round #556 (Div. 1) A. Prefix Sum Primes 给你一堆1,2,你可以任意排序,要求你输出的数列的前缀和中质数个数最大. 发现只有\(2\)是偶 ...
- Codeforces Round #575 (Div. 3) 昨天的div3 补题
Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...
- Codeforces Round #633 (Div. 2)
Codeforces Round #633(Div.2) \(A.Filling\ Diamonds\) 答案就是构成的六边形数量+1 //#pragma GCC optimize("O3& ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- Mutual Training for Wannafly Union #9
A(SPOJ NPC2016A) 题意:给一个正方形和内部一个点,要求从这个点向四边反射形成的路线的长度 分析:不断做对称,最后等价于求两个点之间的距离 B(CF480E) 题意:求01矩阵内由0组成 ...
- MySQL主从复制搭建教程收集(待实践)
先收集一下,后续再搭建测试. https://zhangge.net/4019.html http://www.cnblogs.com/jiangwenju/p/6098974.html http:/ ...
- CSS头像右上角的讨厌红点
就是这个讨厌的红点,如图: 说明: 1.主要用到position定位: 2.使用border-radius画圆角: 源码: <!DOCTYPE html> <html> < ...
- 详细图解mongodb 3.4.1 win7x64安装
原文:http://www.cnblogs.com/yucongblog/p/6895983.html 详细图解,记录 win7 64 安装mongo数据库的过程.安装的版本是 MongoDB-win ...
- How to force immediate stop of threads in Jmeter servers如何在jmeter执行完,立即停止jmeter
https://stackoverflow.com/questions/38900315/how-to-force-immediate-stop-of-threads-in-jmeter-server ...
- Django学习系列之重写User模型和登录验证
重写User模型 Django内置的User模型可能不适合某些项目,我们可能要基于内置的添加一些字段 创建users app startapp users 修改settings.py配置文件,覆盖默认 ...
- [Jest] Automate your migration to Jest using codemods
Jest is a fantastic testing library, but maybe you've been putting off the switch because migrating ...
- yarn之安装依赖包
安装依赖关系 yarn install用于安装项目的所有依赖项.依赖关系从您的项目package.json文件中检索,并存储在yarn.lock文件中. 开发包时,安装依赖关系最常见的是在 您刚刚检出 ...
- 在Linux(centos)上安装PHP的mongodb扩展 成功试过的
到http://pecl.php.net/package/mongo下载相应的mongodb客户端,本例为1.2.1# wget http://pecl.php.net/get/mongo-1.2.1 ...
- [计算机故障]笔记本无法启动,开机启动出现“Operating System Not Found”无法进系统
背景介绍:同事的一台索尼的笔记本,安装XP.开机启动出现“Operating System Not Found”无法进系统 诊断: 初步判断硬盘故障.但听声音,没有异响. 开机按F2进入BIOS设置. ...