This is Dijkstra's algorithm in its purest form. Start from node k with distance . Use a min-heap (priority queue) to always process the closest unvisited node next.
For each node you pop from the heap, relax its neighbors: if dist[node] + weight < dist[neighbor], update and push the neighbor. Once you've visited all reachable nodes, the answer is the maximum distance value.
If any node still has distance infinity after Dijkstra completes, return -1 because it's unreachable from k.