diff --git "a/cmkim/\354\235\264\352\262\203\354\235\264 \354\267\250\354\227\205\354\235\204 \354\234\204\355\225\234 \354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270\353\213\244/\352\262\275\354\237\201\354\240\201 \354\240\204\354\227\274_344p.py" "b/cmkim/\354\235\264\352\262\203\354\235\264 \354\267\250\354\227\205\354\235\204 \354\234\204\355\225\234 \354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270\353\213\244/\352\262\275\354\237\201\354\240\201 \354\240\204\354\227\274_344p.py" new file mode 100644 index 0000000..0f37efb --- /dev/null +++ "b/cmkim/\354\235\264\352\262\203\354\235\264 \354\267\250\354\227\205\354\235\204 \354\234\204\355\225\234 \354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270\353\213\244/\352\262\275\354\237\201\354\240\201 \354\240\204\354\227\274_344p.py" @@ -0,0 +1,59 @@ +from collections import deque +import heapq + +n, k = map(int, input().split()) +arr = [[]] + +temp = [] +q = deque() +heap = [] +def dfs(count): + while q: + virus, x, y = q.popleft() + for i in range(4): + nx, ny = x + dx[i], y + dy[i] + if 0 < nx <= n and 0 < ny <= n: + if arr[nx][ny] == 0: + arr[nx][ny] = virus + q.append((virus, nx, ny)) + count -= 1 + + if count == 0: + return + + +dx = [-1, 1, 0, 0] # 상하좌우 +dy = [0, 0, -1, 1] + +for i in range(1, n+1): + arr.append(list(map(int, input().split()))) + arr[i].insert(0, 0) + for j in range(n+1): + if arr[i][j]: + temp.append((arr[i][j], i, j))# 바이러스 종류, 행, 열 + #heapq.heappush(heap, (arr[i][j], (i, j))) + #q.append((arr[i][j], i, j))# 바이러스 종류, 행, 열 + + +count = 1 +while True: # 너무 무식하게 넣었는데 더 깔끔한 방법은 없을까? + for i in range(len(temp)): + if temp[i][0] == count: + q.append((temp[i][0], temp[i][1], temp[i][2])) + count += 1 + if count > k: + break + + + +s, x, y = map(int, input().split()) + +for i in range(s): + dfs(len(q)) + +print(arr[x][y]) + + + + + diff --git "a/cmkim/\354\235\264\352\262\203\354\235\264 \354\267\250\354\227\205\354\235\204 \354\234\204\355\225\234 \354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270\353\213\244/\355\212\271\354\240\225\352\261\260\353\246\254\354\235\230 \353\217\204\354\213\234\354\260\276\352\270\260_339p.py" "b/cmkim/\354\235\264\352\262\203\354\235\264 \354\267\250\354\227\205\354\235\204 \354\234\204\355\225\234 \354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270\353\213\244/\355\212\271\354\240\225\352\261\260\353\246\254\354\235\230 \353\217\204\354\213\234\354\260\276\352\270\260_339p.py" new file mode 100644 index 0000000..ce95b65 --- /dev/null +++ "b/cmkim/\354\235\264\352\262\203\354\235\264 \354\267\250\354\227\205\354\235\204 \354\234\204\355\225\234 \354\275\224\353\224\251 \355\205\214\354\212\244\355\212\270\353\213\244/\355\212\271\354\240\225\352\261\260\353\246\254\354\235\230 \353\217\204\354\213\234\354\260\276\352\270\260_339p.py" @@ -0,0 +1,40 @@ +from _collections import deque + +n, m, k, x = map(int, input().split()) + +arr = [[] for _ in range(n+1)] +dist = [1000000000] * (n+1) + +for i in range(m): + a, b = map(int, input().split()) + arr[a].append(b) + #arr[b].append(a) + +q = deque() +q.append((x, 1)) + +while q: + start, cost = q.popleft() + + for end in arr[start]: + dist[end] = min(dist[end], cost) + q.append((end, cost+1)) + +count = 0 +for i in range(1, n+1): + if dist[i] == k: + print(i) + count += 1 + +if not count: + print(-1) + + + +''' +4 4 2 1 +1 2 +1 3 +2 3 +2 4 +''' \ No newline at end of file