[Coding Test]/[백준]

    [백준] 1697 파이썬(python) : 숨바꼭질 - (★)

    [백준] 1697 파이썬(python) : 숨바꼭질 - (★)

    1697번 : 숨바꼭질 from collections import deque n, k = map(int, input().split()) MAX = 10**5 #1 distance = [0] * (MAX + 1) #2 def bfs(): q = deque() q.append(n) while q: x = q.popleft() if x == k: #3 print(distance[x]) break for nx in (x-1, x+1, 2*x): #4 if 0

    [백준] 7569 파이썬(python) : 토마토 - 3차원배열

    [백준] 7569 파이썬(python) : 토마토 - 3차원배열

    7569번: 토마토 import sys from collections import deque m, n, h = map(int, sys.stdin.readline().split()) q = deque() graph = [ [list(map(int, sys.stdin.readline().split())) for _ in range(n) ] for _ in range(h) ] #1 dx = [ -1, 1, 0, 0, 0, 0 ] #2 dy = [ 0, 0, -1, 1, 0, 0 ] dz = [ 0, 0, 0, 0, -1, 1 ] for i in range(h): #3 for j in range(n): for k in range(m): if graph[i][j][k] == 1: q.append((i, j, k)..

    [백준] 7576 파이썬(python) : 토마토 - (★)

    [백준] 7576 파이썬(python) : 토마토 - (★)

    7576번: 토마토 from collections import deque import sys m, n = map(int, input().split()) graph = [ list(map(int, sys.stdin.readline().split())) for _ in range(n) ] q = deque() res = 0 #1 dx = [ 0, 0, -1, 1 ] dy = [ -1, 1, 0, 0 ] def bfs(): while q: x, y = q.popleft() for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0

    [백준] 1012 파이썬(python) : 유기농 배추

    [백준] 1012 파이썬(python) : 유기농 배추

    1012번 : 유기농 배추  dfs 나의풀이)import syssys.setrecursionlimit(10**9) #1t = int(sys.stdin.readline())for _ in range(t): m, n, k = map(int, sys.stdin.readline().split()) graph = [ [0]*m for _ in range(n) ] #2 visit = [ [False]*m for _ in range(n) ] #2 cnt = 0 dx = [ 0, 0, -1, 1 ] #3 dy = [ -1, 1, 0, 0 ] for _ in range(k): a, b = map(int, sys.stdin.readline().split()) ..

    [백준] 2667 파이썬(python) : 단지번호붙이기 - (★)

    [백준] 2667 파이썬(python) : 단지번호붙이기 - (★)

    2667번 : 단지번호붙이기 내가 푼 dfs풀이) import sys n = int(sys.stdin.readline()) graph = [ list(map(int, sys.stdin.readline().rstrip())) for _ in range(n) ] visit = [ [False]*(n+1) for _ in range(n+1) ] #1 dx = [ 0, 0, -1, 1 ] #2 dy = [ -1, 1, 0, 0 ] cnt_arr = [] #3 def dfs(x, y): #4 global cnt visit[x][y] = True #5 for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0

    [백준] 2606 파이썬(python) : 바이러스

    [백준] 2606 파이썬(python) : 바이러스

    2606번 : 바이러스   나의 풀이(dfs)import sysn = int(input())m = int(input())graph = [ [] for _ in range(n+1)]for _ in range(m): a, b = map(int, sys.stdin.readline().split()) graph[a].append(b) graph[b].append(a)visit = [0] * (n+1) #1cnt = 0def dfs(v): global cnt visit[v] = 1 for i in graph[v]: if visit[i] == 0: cnt += 1 dfs(i)dfs(1) #2print(cnt)  dfs로 문제를 해결..