<filename>Graph/find_route.py
# https://www.acmicpc.net/problem/11403

n = int(input())
graph = [list(map(int, input().split())) for i in range(n)]

for k in range(n):
    for i in range(n):
        for j in range(n):
            if graph[i][k] and graph[k][j]:
                graph[i][j] = 1

for i in range(n):
    for j in range(n):
        print(graph[i][j], end=" ")

    print()
<filename>Graph/find_route.py
# https://www.acmicpc.net/problem/11403

n = int(input())
graph = [list(map(int, input().split())) for i in range(n)]

for k in range(n):
    for i in range(n):
        for j in range(n):
            if graph[i][k] and graph[k][j]:
                graph[i][j] = 1

for i in range(n):
    for j in range(n):
        print(graph[i][j], end=" ")

    print()
# https://www.acmicpc.net/problem/11403