-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14938.py
More file actions
47 lines (38 loc) · 1.04 KB
/
14938.py
File metadata and controls
47 lines (38 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#solved.ac
#골드4
#다익스트라
#서강 그라운드
#14938
#bfs 풀이
from collections import deque
#지역의 개수,수색 범위, 길의 개수
n,m,r = map(int,input().split())
itemList = [0]+list(map(int,input().split()))
graph = [[] for _ in range(n+1)]
for i in range(r):
tmp = list(map(int,input().split()))
graph[tmp[0]].append((tmp[1],tmp[2]))
graph[tmp[1]].append((tmp[0],tmp[2]))
def bfs(start):
sum = itemList[start]
q = deque()
q.append((start,0))
visited[start] = True
while q:
v, dist = q.popleft()
for info in graph[v]:
node = info[0]
cost = info[1]
#거리 만족 시
if dist+cost <= m:
#방문안한 노드만 더해줌
if not visited[node]:
sum += itemList[node]
q.append((node,dist+cost))
visited[node] = True
return sum
maxItem = 0
for i in range(1,n+1):
visited = [False for _ in range(n+1)]
maxItem = max(maxItem,bfs(i))
print(maxItem)