Post

[BOJ] 11403. ๊ฒฝ๋กœ์ฐพ๊ธฐ(python)

๐Ÿ“Œ๋ฌธ์ œ

Alt text

๐Ÿ’ช์•„์ด๋””์–ด

  1. ์ž…๋ ฅ๋ฐ›์€ ๊ทธ๋ž˜ํ”„ ๊ฐ„์„  ์—ฐ๊ฒฐํ•˜๊ธฐ
  2. ์„œ๋กœ ์—ฐ๊ฒฐ๋œ ๊ฐ„์„  ์ฒดํฌํ•˜๊ธฐ
    a์™€ b๊ฐ€ ์—ฐ๊ฒฐ๋˜๊ณ  b์™€ c๊ฐ€ ์—ฐ๊ฒฐ๋œ ์ƒํƒœ์ด๋ฉด a์™€ c๋„ ์—ฐ๊ฒฐ๋œ ์ƒํƒœ์ด๋‹ค. ์ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ทธ๋ž˜ํ”„ ๋…ธ๋“œ ๊ฐ„์˜ ์—ฐ๊ฒฐ์ด ๋๋Š”์ง€ ์ฒดํฌ ํ›„ ์ƒํƒœ๋ฅผ ํ‘œ์‹œํ•ด์ค€๋‹ค.

๐Ÿฅ‚์ฝ”๋“œ

1
2
3
4
5
6
7
8
9
10
11
12
13
import sys; input = sys.stdin.readline
n = int(input())
graph = []
for _ in range(n):
    graph.append(list(map(int,input().split())))

for k in range(n):
    for i in range(n):
        for j in range(n):
            if graph[i][k]==1 and graph[k][j]==1:
                graph[i][j]=1
for g in graph:
    print(' '.join(map(str,g)))
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.