Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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])





Original file line number Diff line number Diff line change
@@ -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
'''