[BaekJoon] 백준 알고리즘 4963번 / 섬의 개수 / DFS / Python
import sys sys.setrecursionlimit(10**6) dr = [-1, -1, -1, 0, 0, 1, 1, 1] dc = [-1, 0, 1, -1, 1, -1, 0, 1] def dfs(a, b): global island, visited visited[a][b] = 1 for dir in range(8): nr = dr[dir] + a nc = dc[dir] + b if nr >= 0 and nr = 0 and nc < w: if arr[nr][nc] == 1 and visited[nr][nc] == 0: dfs(nr,nc) while True: island = 0 w, h = map(int,input().split()) if w == 0 and h == 0 : ..
2023. 3. 25.