๋ฌธ์
๋ฐฑ์ค ์จ๋ผ์ธ ์ ์ง - 18243๋ฒ
ํ์ด ๊ณผ์
์
๋ ฅ์ผ๋ก ์ฃผ์ด์ง ์น๊ตฌ ๊ด๊ณ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์์ ์ธ์ ๋คํธ์ํฌ
๋ฅผ ๋ง์กฑํ๋์ง ํ๋จํ๋ ๋ฌธ์ ์
๋๋ค.
์๋ก ๋ค๋ฅธ ๋ ์น๊ตฌ์ฌ์ด์ ๋๋ฌํ๊ธฐ ์ํ ๊ฑฐ๋ฆฌ๋ฅผ ๋ชจ๋ ๊ณ์ฐํด์ 6๋จ๊ณ ์ดํ์ธ์ง ํ์ธํ๋ฉด ๋ฉ๋๋ค.
์ด๋ฅผ ์ํด ํ๋ก์ด๋ ์์ฌ
์๊ณ ๋ฆฌ์ฆ์ ์ฌ์ฉํด์ ๋ชจ๋ ์ ์ ๊ฐ์ ๊ฑฐ๋ฆฌ ๊ฐ์ O(N^3)
์ ์๊ฐ ๋ณต์ก๋๋ก ๊ณ์ฐํ๋ฉด ๋ฉ๋๋ค.
์ฝ๋
import sys
N, K = list(map(int, sys.stdin.readline().split()))
edges = [list(map(int, sys.stdin.readline().split())) for _ in range(K)]
def make_graph():
graph = [[sys.maxsize] * N for _ in range(N)]
for frm, to in edges:
graph[frm - 1][to - 1] = 1
graph[to - 1][frm - 1] = 1
return graph
def floyd(graph):
for v in range(N):
graph[v][v] = 0
for k in range(N):
for u in range(N):
for v in range(N):
graph[u][v] = min(graph[u][v], graph[u][k] + graph[k][v])
def solution():
graph = make_graph()
floyd(graph)
for frm in range(N):
for to in range(N):
if graph[frm][to] > 6:
return 'Big World!'
return 'Small World!'
print(solution())
๋ฐ์ํ
'๐ algorithm > boj' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ 1543 - ๋ฌธ์ ๊ฒ์ (0) | 2021.03.18 |
---|---|
BOJ 11403 - ๊ฒฝ๋ก ์ฐพ๊ธฐ (0) | 2021.03.18 |
BOJ 18238 - ZOAC2 (0) | 2021.03.18 |
BOJ 14754 - Pizza Boxes (0) | 2021.03.18 |
BOJ 15723 - n๋จ ๋ ผ๋ฒ (0) | 2021.03.18 |
๐ฌ ๋๊ธ