Skip to content

Commit

Permalink
Merge pull request #64 from AlgoLeadMe/13-fnzksxl
Browse files Browse the repository at this point in the history
13-fnzksxl
  • Loading branch information
fnzksxl authored Apr 10, 2024
2 parents 14500e3 + be04126 commit 67a75ed
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions fnzksxl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
| 10์ฐจ์‹œ | 2024-03-07 | ๊ตฌํ˜„ | [๋‚˜๋ฌด ์žฌํ…Œํฌ](https://www.acmicpc.net/problem/16235) | [#52](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/52) |
| 11์ฐจ์‹œ | 2024-03-10 | ํˆฌํฌ์ธํ„ฐ | [๋ณด์„ ์‡ผํ•‘](https://school.programmers.co.kr/learn/courses/30/lessons/67258) | [#56](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/56) |
| 12์ฐจ์‹œ | 2024-03-13 | ๋ฒจ๋งŒํฌ๋“œ | [ํƒ€์ž„๋จธ์‹ ](https://www.acmicpc.net/problem/11657) | [#](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/58) |
| 13์ฐจ์‹œ | 2024-03-20 | ๋‹ค์ต์ŠคํŠธ๋ผ | [์„œ๊ฐ•๊ทธ๋ผ์šด๋“œ](https://www.acmicpc.net/problem/14938) | [#64](https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/64) |
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import sys
from heapq import *

input = sys.stdin.readline

def dijkstra(graph, start):
distance = [float('inf') for _ in graph]
distance[start] = 0
queue = []
heappush(queue, [distance[start], start])

while queue:
cur_dist, cur_dest = heappop(queue)

if distance[cur_dest] < cur_dist:
continue

for new_dest, new_dist in graph[cur_dest]:
dist = cur_dist + new_dist
if dist < distance[new_dest]:
distance[new_dest] = dist
heappush(queue, [dist, new_dest])

return distance


items = []
N, M, R = map(int, input().split())

item_weight = list(map(int, input().split()))
graph = [[] for _ in range(N+1)]

for _ in range(R):
start, end, weight = map(int, input().split())
graph[start].append((end, weight))
graph[end].append((start, weight))

for item in range(1, len(graph)):
result = dijkstra(graph, item)
can_get = 0
for i in range(len(result)):
if result[i] <= M:
can_get += item_weight[i-1]
items.append(can_get)

print(max(items))

0 comments on commit 67a75ed

Please sign in to comment.