We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8c58e21 commit 15dd873Copy full SHA for 15dd873
1 file changed
live10/test106/문제1/박희경.py
@@ -0,0 +1,31 @@
1
+import sys
2
+
3
4
+input = sys.stdin.readline
5
6
+n = int(input()) # 도시 개수
7
+m = int(input()) # 버스 개수
8
9
+graph = [[float('inf')] * n for _ in range(n)]
10
+for _ in range(m):
11
+ start, end, cost = map(int, input().split())
12
13
+ graph[start - 1][end - 1] = min(cost, graph[start - 1][end - 1])
14
15
+for k in range(n):
16
+ for i in range(n):
17
+ for j in range(n):
18
+ if i == j:
19
+ graph[i][j] = 0
20
+ continue
21
+ if graph[i][k] != float('inf') and graph[k][j] != float('inf'):
22
+ graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j])
23
24
+for row in graph:
25
+ res = []
26
+ for x in row:
27
+ if x == float('inf'):
28
+ res.append(0)
29
+ else:
30
+ res.append(x)
31
+ print(*res)
0 commit comments