This is the canonical Dijkstra's algorithm problem. Single-source shortest path in a weighted graph is a fundamental algorithm.
Enable JavaScript for the full StreamPrep guide.