Skip to content
Back to libraryPart 3 · Graphs and dynamic programming

3.3Shortest paths

Before you start

It helps to have read 3.1 Graph search: BFS and DFS and 1.2 Complexity and limits. Overall level: Intermediate.

Practice: Shortest paths

0 of 4 solved

About these problems

Apply, Connect, Reason and Stretch describe difficulty within this topic, not an official contest rating. Open any problem in any order; reading the chapter first is optional.

  1. 1Directed travel timesA directed graph has n vertices, numbered 1 to n, and m edges with nonnegative weights. Find the shortest distance from vertex 1 to every vertex. Print -1 for unreachable vertices.ApplyNot started
  2. 2Cheapest undirected routeAn undirected graph has n vertices, numbered 1 to n, and m edges with nonnegative weights. Find the minimum cost of a route from vertex 1 to vertex n. Print -1 if vertex n is unreachable.ConnectNot started
  3. 3All-pairs travel deskA small undirected graph has n vertices, numbered 1 to n, and m edges with nonnegative weights. Print the minimum route cost from vertex a to vertex b for each of q queries a b, or -1 if b cannot be reached from a. The cost from a vertex to itself is 0.ReasonNot started
  4. 4One discounted edgeA directed graph has n vertices, numbered 1 to n, and m edges with nonnegative weights. Find the cheapest route cost from vertex 1 to vertex n if you may discount at most one edge on the route, changing its weight w to floor(w/2). The discount is optional. Print -1 if no route exists.StretchNot started

Read the lesson