티스토리 뷰

"""
 *packageName    : 
 * fileName       : 16173_점프왕쩰리_S4
 * author         : ipeac
 * date           : 2022-04-13
 * description    :
 * ===========================================================
 * DATE              AUTHOR             NOTE
 * -----------------------------------------------------------
 * 2022-04-13        ipeac       최초 생성
 """
import sys

sys.setrecursionlimit(10 ** 5)


def dfs(x, y):
      if x < 0 or x >= n or y < 0 or y >= n:
            return False
      if visited[x][y]:
            return False
      if graph[x][y] == -1:
            print("HaruHaru")
            sys.exit(0)
      
      visited[x][y] = True
      dfs(x + graph[x][y], y)
      dfs(x, y + graph[x][y])
      return True








n = int(input())
graph = [list(map(int, input().split())) for _ in range(n)]
visited = [list([False] * n) for _ in range(n)]

print("graph : %s " % graph)
print("visited : %s " % visited)

if dfs(0, 0):
      print("Hing")

-dfs 사용

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함