14938. 서강그라운드
14938번: 서강그라운드
예은이는 요즘 가장 인기가 있는 게임 서강그라운드를 즐기고 있다. 서강그라운드는 여러 지역중 하나의 지역에 낙하산을 타고 낙하하여, 그 지역에 떨어져 있는 아이템들을 이용해 서바이벌을
www.acmicpc.net
- 내 풀이
- 전형적인 다익스트라 문제
#아이템 몇개있는지
#양방향
#지역개수n, 수색범위m, 길 개수 r
import heapq
n,m,r=map(int,input().split())
item=list(map(int,input().split()))
graph=[[] for _ in range(n+1)]
answer=0
def solve(start):
q=[]
result = [int(1e9) for _ in range(n + 1)]
heapq.heappush(q, (0,start))
result[start]=0
while q:
v,x=heapq.heappop(q)
for gp in graph[x]:
time, end=gp
if end == start: continue
if result[end]>v+time:
result[end]=v+time
heapq.heappush(q, (result[end], end))
count(result)
def count(result):
global answer
tmp=0
for i in range(1,n+1):
if result[i]<=m:
tmp+=item[i-1]
answer=max(answer,tmp)
for i in range(r):
a,b,t=map(int,input().split())
graph[a].append((t,b))
graph[b].append((t,a))
for i in range(1,n+1):
solve(i)
print(answer)'코딩테스트 > BOJ' 카테고리의 다른 글
| [백준] [DP] 17212. 달나라 토끼를 위한 구매대금 지불 도우미 (0) | 2023.05.10 |
|---|---|
| [백준] [부분집합] 6603. 로또 (0) | 2023.05.09 |
| [백준] [위상정렬] 1516. 게임 개발 (0) | 2023.05.06 |
| [백준] [DP] [최장증가수열] 2565. 전깃줄 (0) | 2023.05.06 |
| [백준] [이진 탐색] [최장증가수열] 12015. 가장 긴 증가하는 부분 수열 2 (0) | 2023.05.06 |