
문제 https://www.acmicpc.net/problem/2667 2667번: 단지번호붙이기 과 같이 정사각형 모양의 지도가 있다. 1은 집이 있는 곳을, 0은 집이 없는 곳을 나타낸다. 철수는 이 지도를 가지고 연결된 집의 모임인 단지를 정의하고, 단지에 번호를 붙이려 한다. 여 www.acmicpc.net 코드 import collections n = int(input()) graph = [list(map(int,input().strip())) for _ in range(n)] check = [[False]*n for _ in range(n)] def bfs(x,y): count = 1 check[x][y] = True queue = collections.deque() queue.append((..

문제 https://www.acmicpc.net/problem/1012 1012번: 유기농 배추 차세대 영농인 한나는 강원도 고랭지에서 유기농 배추를 재배하기로 하였다. 농약을 쓰지 않고 배추를 재배하려면 배추를 해충으로부터 보호하는 것이 중요하기 때문에, 한나는 해충 방지에 www.acmicpc.net 코드 import collections t = int(input()) def bfs(x,y): queue = collections.deque() queue.append((x,y)) dx, dy = [-1, 1, 0, 0], [0, 0, -1, 1] while queue: x, y = queue.popleft() # 주변 4방향을 모두 확인한다. for i in range(4): nx = dx[i] + x..

문제 https://www.acmicpc.net/problem/14502 14502번: 연구소 인체에 치명적인 바이러스를 연구하던 연구소에서 바이러스가 유출되었다. 다행히 바이러스는 아직 퍼지지 않았고, 바이러스의 확산을 막기 위해서 연구소에 벽을 세우려고 한다. 연구소는 크 www.acmicpc.net 코드 import collections, sys n, m = map(int, input().split()) graph = [list(map(int, sys.stdin.readline().strip().split())) for _ in range(n)] curMax = 0 def bfs(): global curMax check = [[-1] * m for _ in range(n)] dx, dy = [-1,..

문제 https://www.acmicpc.net/problem/14889 14889번: 스타트와 링크 예제 2의 경우에 (1, 3, 6), (2, 4, 5)로 팀을 나누면 되고, 예제 3의 경우에는 (1, 2, 4, 5), (3, 6, 7, 8)로 팀을 나누면 된다. www.acmicpc.net 코드 n = int(input()) graph = [list(map(int, input().split(" "))) for _ in range(n)] curMin = 10000000 check = [False] * n def recursive(index, count1, count2, sum1, sum2): global curMin if index == n: if count1 == count2: curMin = mi..