-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1197.py
More file actions
24 lines (24 loc) · 770 Bytes
/
1197.py
File metadata and controls
24 lines (24 loc) · 770 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
from collections import deque
v = 0
e = 0
graph = [[] for i in range(10001)]
ans = [2147483647 for i in range(10001)]
visit = [False for i in range(10001)]
ans[1] = 0
visit[1] = True
def main():
v, e = map(int, input().split())
for i in range(e):
tmp1, tmp2, tmp3 = map(int, input().split())
graph[tmp1].append([tmp2, tmp3])
graph[tmp2].append([tmp1, tmp3])
for i in range(1, v+1):
for j in range(len(graph[i])):
if visit[graph[i][j][0]] == False:
visit[graph[i][j][0]] = True
ans[graph[i][j][0]] = ans[i] + graph[i][j][1]
else:
ans[graph[i][j][0]] = min(ans[graph[i][j][0]], ans[i]+graph[i][j][1])
print(ans[v])
if __name__ == "__main__":
main()