CodeForces 144DMissile Silos
来源:互联网 发布:现有sql server 实例 编辑:程序博客网 时间:2024/06/06 18:49
A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missiles. The exact position of the Super Duper Secret Missile Silos is kept secret but Bob managed to get hold of the information. That information says that all silos are located exactly at a distance l from the capital. The capital is located in the city with number s.
The documents give the formal definition: the Super Duper Secret Missile Silo is located at some place (which is either city or a point on a road) if and only if the shortest distance from this place to the capital along the roads of the country equals exactly l.
Bob wants to know how many missile silos are located in Berland to sell the information then to enemy spies. Help Bob.
The first line contains three integers n, m and s (2 ≤ n ≤ 105, , 1 ≤ s ≤ n) — the number of cities, the number of roads in the country and the number of the capital, correspondingly. Capital is the city no. s.
Then m lines contain the descriptions of roads. Each of them is described by three integers vi, ui, wi (1 ≤ vi, ui ≤ n, vi ≠ ui, 1 ≤ wi ≤ 1000), where vi, ui are numbers of the cities connected by this road and wi is its length. The last input line contains integer l (0 ≤ l ≤ 109) — the distance from the capital to the missile silos. It is guaranteed that:
- between any two cities no more than one road exists;
- each road connects two different cities;
- from each city there is at least one way to any other city by the roads.
Print the single number — the number of Super Duper Secret Missile Silos that are located in Berland.
4 6 11 2 11 3 32 3 12 4 13 4 11 4 22
3
5 6 33 1 13 2 13 4 13 5 11 2 64 5 84
3
In the first sample the silos are located in cities 3 and 4 and on road (1, 3) at a distance 2 from city 1 (correspondingly, at a distance 1 from city 3).
In the second sample one missile silo is located right in the middle of the road (1, 2). Two more silos are on the road (4, 5) at a distance 3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4.
找出一个图里几个点离起点的最短路是L,求最短路的同时考虑判断每条边上是否有点满足条件。
#include<map>#include<set>#include<ctime>#include<cmath>#include<queue>#include<bitset>#include<string>#include<vector>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<functional>using namespace std;#define ms(x,y) memset(x,y,sizeof(x))#define rep(i,j,k) for(int i=j;i<=k;i++)#define per(i,j,k) for(int i=j;i>=k;i--)#define loop(i,j,k) for (int i=j;i!=-1;i=k[i])#define inone(x) scanf("%d",&x)#define intwo(x,y) scanf("%d%d",&x,&y)#define inthr(x,y,z) scanf("%d%d%d",&x,&y,&z)#define infou(x,y,z,p) scanf("%d%d%d%d",&x,&y,&z,&p)#define lson x<<1,l,mid#define rson x<<1|1,mid+1,r#define mp(i,j) make_pair(i,j)#define fi first#define se secondtypedef long long LL;typedef pair<int, int> pii;const int low(int x) { return x&-x; }const int INF = 0x7FFFFFFF;const int N = 2e5 + 10;const double eps = 1e-10;int n, m, s, L, x, y, z;int ft[N], nt[N], u[N], v[N], sz = 0;int d[N], vis[N];int main(){inthr(n, m, s);rep(i, 1, n) ft[i] = -1, d[i] = INF, vis[i] = 0;rep(i, 1, m){inthr(x, y, z);u[sz] = y; v[sz] = z; nt[sz] = ft[x]; ft[x] = sz++;u[sz] = x; v[sz] = z; nt[sz] = ft[y]; ft[y] = sz++;}inone(L); int ans = d[s] = 0;priority_queue<pii, vector<pii>, greater<pii> > p;p.push(make_pair(0, s));while (!p.empty()){pii q = p.top(); p.pop();if (vis[q.se]) continue;vis[q.se] = 1;if (q.fi == L) ans++;loop(i, ft[q.se], nt){if (d[u[i]] > q.fi + v[i]){p.push(make_pair(d[u[i]] = q.fi + v[i], u[i]));}if (vis[u[i]]){if (d[u[i]] < L && d[u[i]] + v[i] > L){int k = d[u[i]] + v[i] - L;ans += q.fi + k >= L;}if (q.first < L && q.fi + v[i] > L){int k = q.fi + v[i] - L;ans += d[u[i]] + k >= L;}if (d[u[i]] < L && d[u[i]] + v[i] > L)if (q.first < L && q.fi + v[i] > L){ans -= q.fi + d[u[i]] + v[i] == L + L;}}}}printf("%d\n", ans);return 0;}
- CodeForces 144DMissile Silos
- Codeforces 144D: Missile Silos
- Codeforces 144D Missile Silos
- codeforces 144D Missile Silos spfa
- Codeforces 144D. Missile Silos 最短路
- Codeforces 144D. Missile Silos【dijkstra】
- codeforces 144 D. Missile Silos 最短路
- codeforces D. Missile Silos
- Codeforces 144D Missile Silos(SPFA最短路)
- Codeforces 144 D Missile Silos【最短路SPFA+枚举】
- 144D Missile Silos (data structures, graphs, shortest paths)
- CF 144D Missile Silos [最短路+想法]
- Codeforces Round #103 (Div. 2) D. Missile Silos(spfa + 枚举边)
- Codeforces Round #103 (Div. 2)---D. Missile Silos(最短路+枚举边)
- Network virtualization, management silos and missed opportunities
- CF144D Missile Silos SPFA最短路
- Goodbye, Silos: The Benefits of Converged Data Centers
- 最简单易用的verilog学习练习工具silos初次使用。
- POJ-2182 Lost Cows 简单的想法
- 华为机试-查找输入整数二进制中1的个数
- 如何评价小智从主播成千万大股东
- Android 6.0+ 运行时权限——EasyPermissions源码解析
- Linux学习——用户管理命令
- CodeForces 144DMissile Silos
- 203. Remove Linked List Elements
- bzoj [1005] [HNOI2008]明明的烦恼
- RAC扩展──异步filter、map
- 七种常见阈值分割代码(Otsu、最大熵、迭代法、自适应阀值、手动、迭代法、基本全局阈值法)
- czg.sh(烧写SD脚本)
- Skinned Mesh 原理解析和一个最简单的实现示例 作者:n5 Email: happyfirecn##yahoo.com.cn Blog: http://blog.csdn.net/n5
- LintCode | 167. 链表求和
- POJ 2583 Series Determination G++