[백준 5022번] 연결 (Python3)
from collections import * dy = [1,-1,0,0]; dx = [0,0,1,-1] def BFS(A1,A2): dq = deque([[*A1,*A1,0]]) while dq: y,x,ylast,xlast,d = dq.popleft() if visited[y][x]: continue visited[y][x] = ylast,xlast if [y,x] == A2: return d for i in range(4): y1,x1 = y+dy[i],x+dx[i] if N>y1>=0 and M>x1>=0: dq.append((y1,x1,y,x,d+1)) return 1e6 def solve(A1,A2,B1,B2): global visited visited = [[0]*M for i in rang..
[백준 1824번] 도미노 (Python3)
dy = [1,-1,0,0]; dx = [0,0,1,-1] def DFS(y,x): if visited[y][x]: return visited[y][x] = 1 for y1,x1 in graph[y][x]: if not match[y1][x1]: match[y1][x1] = y,x return 1 for y1,x1 in graph[y][x]: if DFS(*match[y1][x1]): match[y1][x1] = y,x return 1 N,M = map(int,input().split()) graph = [[set() for x in range(M)] for y in range(N)] for y in range(N): for x in range(M): if (y+x)%2: continue for i in..