λ¬Έμ
λ°±μ€ μ¨λΌμΈ μ μ§ - 11403λ²
νμ΄ κ³Όμ
μμμ ν μ μ μμ λ€λ₯Έ λͺ¨λ μ μ κΉμ§μ λλ¬ κ°λ₯μ±μ νλ¨νλ λ¬Έμ μ
λλ€.
λ€λλ€ κ΄κ³μ λλ¬ κ°λ₯μ±μ΄κΈ° λλ¬Έμ κ°κ°μ μ μ μμ DFS
λ₯Ό μννλ λ°©λ²λ μμ§λ§νλ‘μ΄λ μμ¬
μ μ¬μ©ν΄μ ꡬν μλ μμ΅λλ€.
μ½λ
import sys
N = int(input())
graph = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def floyd():
global graph
for k in range(N):
for u in range(N):
for v in range(N):
graph[u][v] = graph[u][v] or (graph[u][k] and graph[k][v])
def solution():
floyd()
for row in graph:
print(*row)
solution()
λ°μν
'π algorithm > boj' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
BOJ 17406 - λ°°μ΄ λ리기 4 (0) | 2021.03.18 |
---|---|
BOJ 1543 - λ¬Έμ κ²μ (0) | 2021.03.18 |
BOJ 18243 - Small World Network (0) | 2021.03.18 |
BOJ 18238 - ZOAC2 (0) | 2021.03.18 |
BOJ 14754 - Pizza Boxes (0) | 2021.03.18 |
π¬ λκΈ