[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.
[BaekJoon] 백준 알고리즘 14502번 / 연구소 / dfs / Python
import sys from collections import deque from itertools import combinations import copy input = sys.stdin.readline N,M = map(int,input().split()) board = [list(map(int,input().split())) for _ in range(N)] # 준비 1 safe_zone = [] virus = [] res = 0 dx = [-1,0,1,0] dy = [0,-1,0,1] # 감염 def BFS(): global res cnt = len(safe_zone)-3 ch_virus = deque([]) for x,y in virus: ch_virus.append((x,y)) while ch..
2023. 3. 18.