From f0f38ca0cdf661eea27b5195491d05db88b2bf25 Mon Sep 17 00:00:00 2001 From: goeom77 <7eom14@gmail.com> Date: Tue, 4 Mar 2025 13:52:38 +0900 Subject: [PATCH] =?UTF-8?q?solved=20=EB=B6=80=EB=8C=80=EB=B3=B5=EA=B7=80?= =?UTF-8?q?=20-=204416.71ms=20137mb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0_\354\227\204\355\230\225\352\267\234.py" | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 "Programmers/\353\266\200\353\214\200\353\263\265\352\267\200/\353\266\200\353\214\200\353\263\265\352\267\200_\354\227\204\355\230\225\352\267\234.py" diff --git "a/Programmers/\353\266\200\353\214\200\353\263\265\352\267\200/\353\266\200\353\214\200\353\263\265\352\267\200_\354\227\204\355\230\225\352\267\234.py" "b/Programmers/\353\266\200\353\214\200\353\263\265\352\267\200/\353\266\200\353\214\200\353\263\265\352\267\200_\354\227\204\355\230\225\352\267\234.py" new file mode 100644 index 0000000..b07bba5 --- /dev/null +++ "b/Programmers/\353\266\200\353\214\200\353\263\265\352\267\200/\353\266\200\353\214\200\353\263\265\352\267\200_\354\227\204\355\230\225\352\267\234.py" @@ -0,0 +1,20 @@ +import heapq +def solution(n, roads, sources, destination): + # n 지역, 길정보 roads, 부대원 위치 sources, 부대위치 destination + answer = [] + dp = [-1]*(n+1) + way = [[] for i in range(n+1)] + for road in roads: + way[road[0]].append(road[1]) + way[road[1]].append(road[0]) + h = [(0,destination)] + while (h): + time, now = heapq.heappop(h) + if (dp[now] == -1): + dp[now] = time + for i in way[now]: + heapq.heappush(h,(time+1,i)) + for i in range(len(sources)): + answer.append(dp[sources[i]]) + + return answer \ No newline at end of file