[백준 11724번] 연결 요소의 개수
n, m = map(int,input().split()) count = 0 graph = [[] for _ in range(n+1)] visited = [False]*(n+1) for _ in range(m): x, y = map(int,input().split()) graph[x].append(y) graph[y].append(x) def dfs(graph,v,visited): if visited[v]: return False visited[v] = True for i in graph[v]: if not visited[i]: dfs(graph,i,visited) return True for i in range(1,n+1): if dfs(graph,i,visited): count += 1 print(co..
2023. 2. 15.
[백준 7576번] 토마토
from collections import deque # 가로(m), 세로(n) m, n = map(int,input().split()) # 토마토가 담긴 상자(2차원 리스트) area = [] # 토마토가 존재하는 위치를 담는 리스트 exist_list = [] # 토마도가 모두 익는 최소 일수(정답) result = 0 # BFS 함수 def bfs(list): global result queue = deque(list) # 익을 수 있는 토마토가 다 익었을 때, 마지막 구역에 저장된 값 depth = 0 while queue: v = queue.popleft() nx = [-1,1,0,0] ny = [0,0,-1,1] for i in range(4): temp_x = v[0] + nx[i] temp..
2023. 2. 14.