Graph Theory37 sections · 1633 units
Open in Course

CSES 1671 Shortest Routes I - Problem Statement

Path reconstruction challenge

You are given a directed weighted graph with nn nodes and mm edges. Find the shortest distance from node 11 to every other node. If a node is unreachable, output 1-1.

Run Dijkstra from node 11. Store the distance array. Print the result for each node from 11 to nn. Constraints: n105n \leq 10^5, m2×105m \leq 2 \times 10^5, weights up to 10910^9. Use long long for distances because the total path weight can exceed 3232-bit range. This is the textbook Dijkstra problem with no hidden tricks.