Skip to content

Commit 15dd873

Browse files
committed
106차 1번 문제풀이
1 parent 8c58e21 commit 15dd873

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)