time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

The first line contains three integers nm 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 viuiwi (1 ≤ vi, ui ≤ nvi ≠ ui,1 ≤ wi ≤ 1000), where viui 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.
Output

Print the single number — the number of Super Duper Secret Missile Silos that are located in Berland.

Examples
input
4 6 1
1 2 1
1 3 3
2 3 1
2 4 1
3 4 1
1 4 2
2
output
3
input
5 6 3
3 1 1
3 2 1
3 4 1
3 5 1
1 2 6
4 5 8
4
output
3
Note

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 1from 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 distance3 from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4.

#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long ll;
const int N = 1e5 + ; struct qnode {
int v;
int c;
qnode(int _v = , int _c = ) : v(_v), c(_c) { }
bool operator < (const qnode &r) const {
return c > r.c;
};
};
struct Edge {
int v, cost;
Edge(int _v = , int _cost = ) : v(_v), cost(_cost) { }
};
vector<Edge> E[N];
bool vis[N];
int dist[N], pre[N]; void Dij(int n, int s) {
memset(vis, false, sizeof vis);
for(int i = ; i <= n; ++i) dist[i] = INF;
priority_queue<qnode> que;
pre[s] = -;
while(!que.empty()) que.pop();
dist[s] = ;
que.push(qnode(s, ));
qnode tmp;
while(!que.empty()) {
tmp = que.top();
que.pop();
int u = tmp.v;
if(vis[u]) continue;
vis[u] = true;
for(int i = ; i < E[u].size(); ++i) {
int v = E[u][i].v;
int cost = E[u][i].cost;
if(!vis[v] && dist[v] > dist[u] + cost) {
dist[v] = dist[u] + cost;
que.push(qnode(v, dist[v]));
pre[v] = u;
}
}
}
}
void addedge(int u, int v, int w) {
E[u].push_back(Edge(v, w));
E[v].push_back(Edge(u, w));
}
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif
int n, m, s, u, v, w, l;
scanf("%d%d%d", &n, &m, &s);
for(int i = ; i < m; ++i) {
scanf("%d%d%d", &u, &v, &w);
addedge(u, v, w);
}
scanf("%d", &l);
Dij(n, s);
int ans = ;
for(int i = ; i <= n; ++i) if(dist[i] == l) ans++;
int res = ;
for(int u = ; u <= n; ++u) {
for(int i = ; i < E[u].size(); ++i) {
int v = E[u][i].v;
int w = E[u][i].cost;
if(dist[u] < l && dist[u] + w > l && w + dist[u] + dist[v] >= * l) res++;
if(dist[v] < l && dist[v] + w > l && w + dist[v] + dist[u] >= * l) res++;
if(dist[u] < l && dist[v] < l && dist[u] + w > l && dist[v] + w > l && (l - dist[u] + l - dist[v] == w)) res--;
}
}
printf("%d\n", ans + res / );
return ;
}

最新文章

  1. 利用CSS背景颜色属性使父级div背景透明同时避免子级标签透明。
  2. 查看文本[Linux]
  3. W3School-CSS 定位 (Positioning) 实例
  4. Python中实现异步并发查询数据库
  5. Eclipse 配置Activiti插件
  6. UINavigationItem和UItabBarItem的区别详解
  7. 学习总结 初步了解HTML课程
  8. POJ 2431 Expedition (STL 优先权队列)
  9. MySQL教程:数据库具体操作
  10. 字符数组什么时候要加&lsquo;\0&rsquo;
  11. 使用Struts2实现文件的上传和下载
  12. openvpn环境搭建
  13. 关于EasyUI中的Tree
  14. InnoDB关键特性之刷新邻接页-异步IO
  15. 34.Linux-printk分析、使用prink调试驱动
  16. 【Unity3D技术文档翻译】第1.0篇 AssetBundles
  17. MERGE INTO无法更新ON中的字段解决办法
  18. paramiko__摘抄
  19. C语言的转义字符
  20. Scrapy基础(五) ------css选择器基础

热门文章

  1. JDBC入门学习
  2. 用swing也可以做出好看的界面
  3. Java Abstract Class &amp; Interface
  4. Linux搭建Nginx
  5. Yii rbac原理和实践
  6. codeforces682A
  7. Java将TXT上的数据转换成excel里面
  8. docker swarm-mode
  9. css单位盘点
  10. 额。。万恶之源就是c