배달
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
- 풀이
- 다익스트라 기본 문제
from collections import deque
def solution(N, road, K):
answer = 0
distance=[float('inf') for _ in range(N+1)]
graph=[[] for _ in range(N+1)]
for a,b,c in road:
graph[a].append((b,c))
graph[b].append((a,c))
def bfs(start):
queue=deque()
distance[start]=0
queue.append(start)
while queue:
cur=queue.popleft()
for nxt,nxt_d in graph[cur]:
if distance[nxt]<=distance[cur]+nxt_d:
continue
distance[nxt]=distance[cur]+nxt_d
queue.append((nxt))
bfs(1)
for val in distance:
if val<=K:
answer+=1
return answer
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
| [프로그래머스][구현] 문자열 압축 (1) | 2025.02.08 |
|---|---|
| [프로그래머스][DFS][백트래킹] 여행경로 (1) | 2025.02.07 |
| [프로그래머스][구현][완전 탐색] 메뉴 리뉴얼 (1) | 2025.02.04 |
| [프로그래머스][그리디] 단속카메라 (0) | 2025.02.04 |
| [프로그래머스] 등산코스 정하기 (1) | 2025.02.02 |