-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaek_1753.py
More file actions
37 lines (30 loc) · 824 Bytes
/
Baek_1753.py
File metadata and controls
37 lines (30 loc) · 824 Bytes
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
import sys
from collections import deque
v, e = map(int, sys.stdin.readline().split())
k = int(sys.stdin.readline())
a = [[] for _ in range(v+1)]
for i in range(e):
x, y, w = map(int, sys.stdin.readline().split())
a[x].append([y, w])
def bfs(k):
b = [987654321 for _ in range(v+1)]
c = deque([[k, 0]])
while True:
print(c)
t = c.popleft()
for i in range(len(a[t[0]])):
u = t[1] + a[t[0]][i][1]
p = a[t[0]][i][0]
if b[p] > u and a[p] != k:
b[p] = u
c.append([p, u])
if len(c) == 0:
return b
ans = bfs(k)
for i in range(1, v+1):
if i == k:
print(0)
elif ans[i] == 987654321:
print("INF")
else:
print(ans[i])