DSA 섹션쉬움

데이크스트라

'Dijkstra' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

가중치 그래프의 시작 노드 start에서 다른 모든 노드까지의 최단 경로를 계산하는 함수 dijkstra(graph, start)을 작성하세요. 그래프는 사전의 인접 목록으로 표시됩니다. 여기서 graph[u][v]u에서 v까지의 방향 간선의 가중치입니다. 최단 거리의 사전을 반환합니다.

제약
  • 1 <= V <= 1000
  • 0 <= E <= 5000
  • Weights are non-negative integers.

Example 1
Input
graph = {0: {1: 4, 2: 1}, 1: {3: 1}, 2: {1: 2, 3: 5}, 3: {}}, start = 0
Output
{0: 0, 1: 3, 2: 1, 3: 4}
Explanation

Shortest distance from 0 to 1 is 3 (via 0->2->1).

Need a Hint?
세트나 힙과 같은 그래프 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.