[백준 2638번] 치즈 (Python3)
import sys input = sys.stdin.readline from collections import deque N,M = map(int,input().split()) dy = [1,-1,0,0] dx = [0,0,1,-1] cheese = [] for i in range(N): cheese.append(list(map(int,input().split()))) def melt(n): dq = deque() dq.append((0,0)) melted = False while dq: y,x = dq.popleft() if cheese[y][x] == n: continue elif cheese[y][x] == -n: cheese[y][x] = n melted = True continue elif ch..
[백준 1865번] 웜홀 (Python3)
import sys input = sys.stdin.readline INF = 2000000000 def BF(start): bf = [INF]*(N+1) bf[start] = 0 for i in range(N): for x1,x2,t in graph: if bf[x2] > bf[x1]+t: bf[x2] = bf[x1]+t if i == N-1: return True return False T = int(input()) for test in range(T): N,M,W = map(int,input().split()) graph = [] for i in range(M): x1,x2,t = map(int,input().split()) graph.append((x1,x2,t)) graph.append((x2,..
[백준 1238번] 파티 (Python3)
import sys input = sys.stdin.readline from collections import deque import heapq INF = sys.maxsize N,M,X = map(int,input().split()) graph = [[] for i in range(N+1)] dij = [[INF]*(N+1) for i in range(N+1)] for i in range(M): x1,x2,t = map(int,input().split()) graph[x1].append((x2,t)) def Dijkstra(start): hq = [] heapq.heappush(hq,(0,start)) while hq: w,now = heapq.heappop(hq) if dij[start][now]
[백준 17144번] 미세먼지 안녕! (Python3)
import sys input = sys.stdin.readline from collections import deque import copy dy = [1,-1,0,0] dx = [0,0,1,-1] N,M,T = map(int,input().split()) room = [] for i in range(N): room.append(list(map(int,input().split()))) def spread(): dq = deque() for i in range(N): for j in range(M): if room[i][j]==-1 or room[i][j]==0: continue s = room[i][j]//5 count = 0 for k in range(4): y = i+dy[k] x = j+dx[k]..
[백준 14938번] 서강그라운드 (Python3)
import sys input = sys.stdin.readline from collections import deque INF = sys.maxsize N,M,R = map(int,input().split()) item = deque(map(int,input().split())) item.appendleft(0) graph = [[INF]*(N+1) for i in range(N+1)] for i in range(R): x1,x2,r = map(int,input().split()) graph[x1][x2] = graph[x2][x1] = r for k in range(1,N+1): for i in range(1,N+1): for j in range(1,N+1): if i == j: graph[i][i]..
[백준 12851번] 연구소 (Python3)
import sys input = sys.stdin.readline from collections import deque from itertools import combinations import copy N,M = map(int,input().split()) roomorg = [] for i in range(N): roomorg.append(list(map(int,input().split()))) dy = [1,-1,0,0] dx = [0,0,1,-1] dq = deque() def virus(): dq = deque() for i in range(N): for j in range(M): if room[i][j] == 2: dq.append((i,j)) room[i][j] = 0 while dq: y,..