ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 11404 |
문제명 | 플로이드 |
레벨 | 골드 4 |
분류 |
그래프, 전체쌍 최단경로 |
시간복잡도 | O(V^3+E) |
인풋사이즈 | V<=100, E<=100,000 |
사용한 언어 | Python 3.11 |
제출기록 | 32140KB / 204ms |
최고기록 | 204ms |
해결날짜 | 2024/03/11 |
"""Solution code for "BOJ 11404. 플로이드".
- Problem link: https://www.acmicpc.net/problem/11404
- Solution link: http://www.teferi.net/ps/problems/boj/11404
"""
import sys
from teflib import graph as tgraph
INF = float('inf')
def main():
n = int(sys.stdin.readline())
m = int(sys.stdin.readline())
mat_graph = [[INF] * n for _ in range(n)]
for _ in range(m):
a, b, c = [int(x) for x in sys.stdin.readline().split()]
if c < mat_graph[a - 1][b - 1]:
mat_graph[a - 1][b - 1] = c
dist_mat = tgraph.all_pairs_shortest_paths(mat_graph)
for l in dist_mat:
print(*(0 if x == INF else x for x in l))
if __name__ == '__main__':
main()