[BOJ] 11403. ๊ฒฝ๋ก์ฐพ๊ธฐ(python)
๐๋ฌธ์
๐ช์์ด๋์ด
- ์
๋ ฅ๋ฐ์ ๊ทธ๋ํ ๊ฐ์ ์ฐ๊ฒฐํ๊ธฐ
- ์๋ก ์ฐ๊ฒฐ๋ ๊ฐ์ ์ฒดํฌํ๊ธฐ
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.