λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
πŸƒ algorithm/boj

BOJ 11403 - 경둜 찾기

by HandHand 2021. 3. 18.

문제

λ°±μ€€ 온라인 저지 - 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

πŸ’¬ λŒ“κΈ€