CF144D.Missile Silos
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
一个名为 Berland 的国家由 n 座城市组成,城市编号为 1 到 n 的整数。其中一些城市由双向道路连接,每条道路具有一定的长度。通过这些道路,任意两座城市之间均存在路径。根据某些“超级无敌文件”(Super Duper Documents),Berland 受“超级无敌导弹”(Super Duper Missiles)保护。超级无敌秘密导弹发射井(Super Duper Secret Missile Silos)的确切位置属于国家机密,但 Bob 设法获取了相关信息。该信息指出:所有发射井均恰好位于距首都距离为 l 的位置。首都位于编号为 s 的城市。
文件给出了如下形式化定义:某处(该处可以是一座城市,也可以是某条道路上的一个点)存在一座超级无敌秘密导弹发射井,当且仅当该处到首都沿道路的最短距离恰好等于 l。
Bob 想知道 Berland 境内共有多少座导弹发射井,以便将该情报出售给敌方间谍。请帮助 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 v__i, u__i, w__i (1 ≤ v__i, u__i ≤ n, v__i ≠ u__i, 1 ≤ w__i ≤ 1000), where v__i, u__i are numbers of the cities connected by this road and w__i 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.
第一行包含三个整数 n、m 和 s(2 ≤ n ≤ 105,
,1 ≤ s ≤ n),分别表示城市的数量、国家中道路的数量以及首都的编号。首都是第 s 号城市。
接下来 m 行描述了道路信息。每行包含三个整数 vi、ui、wi(1 ≤ vi,ui ≤ n,vi = ui,1 ≤ wi ≤ 1000),其中 vi 和 ui 是该道路所连接的两个城市的编号,wi 是该道路的长度。最后一行输入一个整数 l(0 ≤ l ≤ 109),表示从首都到导弹发射井的距离。保证满足以下条件:
- 任意两座城市之间至多存在一条道路;
- 每条道路均连接两个不同的城市;
- 从任一城市出发,均至少存在一条经由道路到达其他任意城市的路径。
输出格式
Print the single number — the number of Super Duper Secret Missile Silos that are located in Berland.
输出唯一的数字——位于贝尔兰的超级绝密导弹发射井的数量。
输入输出样例
输入#1
4 6 1 1 2 1 1 3 3 2 3 1 2 4 1 3 4 1 1 4 2 2
输出#1
3
输入#2
5 6 3 3 1 1 3 2 1 3 4 1 3 5 1 1 2 6 4 5 8 4
输出#2
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.
在第一个样例中,导弹发射井位于城市 3 和城市 4,以及道路 (1,3) 上距城市 1 距离为 2 的位置(即,距城市 3 距离为 1 的位置)。
在第二个样例中,一个导弹发射井恰好位于道路 (1,2) 的中点;另外两个发射井位于道路 (4,5) 上:一个距城市 4 沿朝向城市 5 的方向距离为 3,另一个距城市 5 沿朝向城市 4 的方向距离为 3。
输入解题思路,AI测评打分。不知道怎么写?