Last active
December 17, 2019 05:18
-
-
Save inspirit941/a6b1c06bf662bde73880e3d665fd2b9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict, deque | |
def can_reach(start, des, table): | |
visited = set() | |
queue = deque() | |
queue.append(start) | |
while queue: | |
nxt = queue.popleft() | |
visited.add(nxt) | |
for i in table[nxt]: | |
# 목적지와 일치하는 경우 | |
if i == des: | |
return 1 | |
elif i not in visited: | |
queue.append(i) | |
visited.add(i) | |
# 도착할 수 없는 경우 | |
return 0 | |
def solution(n,signs): | |
table = defaultdict(set) | |
for y in range(n): | |
for x in range(n): | |
if signs[y][x] == 1: | |
table[y].add(x) | |
answer = [[0 for _ in range(n)] for _ in range(n)] | |
for y in range(n): | |
for x in range(n): | |
# y에서 x까지 도착할 수 있는지 검사한다. | |
answer[y][x] = can_reach(y, x, table) | |
return answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment