D. Missile Silos
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 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.
Output
Print the single number — the number of Super Duper Secret Missile Silos that are located in Berland.
Examples
input
Copy
output
Copy
3
input
Copy
output
Copy
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 distance 3from city 4 in the direction to city 5 and at a distance 3 from city 5 to city 4.
题意:
最短距离为len的地方有几个(在边上或者在点上都算)?。
分析:
对于节点上:
直接Dijkstra最短路求出dist[i]来,if(dist[i]==len) ans++
对于边上的点上:
我们枚举每一条边,分为三种情况:
第一种情况点p靠经u:注意这里的靠经是指:dist[u]+|up|<dist[v]+|vp|,不要被表面迷惑
满足上述情况:u距离s的距离小于len,|uv|这条边的距离+dist[u]>len,s经过v经过p的最短距离要大于len
第二种情况点p靠经v,与上述同理
第三种情况p在uv中间,即s经过u到p距离,s经过v到p的距离均为len。(注意p不一定是uv的中点,而是svp=sup,所以在这种情况下p的位置不确定)