-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path74.py
More file actions
54 lines (40 loc) · 2.03 KB
/
74.py
File metadata and controls
54 lines (40 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'''
https://www.spoj.com/problems/MICEMAZE/
Comment
'''
import sys
import queue
def FILE_IO():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
'''____________________________________________________________________________________________'''
INF = 10 ** 9
def dijkstra():
pq = queue.PriorityQueue()
pq.put((0, exit))
dist[exit] = 0
while not pq.empty():
w, u = pq.get()
if w != dist[u]:
continue
for neibor, weight in grp[u]:
if dist[neibor] > w + weight:
dist[neibor] = w + weight
pq.put((dist[neibor], neibor))
#_____main_____
#FILE_IO()
V = int(input())
exit = int(input())
t = int(input())
E = int(input())
grp = [[] for i in range(V + 5)]
dist = [INF]*(V + 5)
for i in range(E):
v, u, w = map(int, input().split())
grp[u].append((v, w))
dijkstra()
cnt = 0;
for i in range(1, V + 1):
if dist[i] <= t:
cnt += 1
print(cnt)