A8459 | Missile Silos
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 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<=10^{5}$ , , $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<=10^{9}$ ) — 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.
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<=10^{9}$ ) — 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.
输入输出样例
输入 #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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted