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

3.1Graph search: BFS and DFS

Before you start

It helps to have read 1.3 Arrays and strings and 2.4 Recursion and backtracking. Overall level: Intermediate.

Practice: Graph search: BFS and DFS

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. 1Reachable stationsAn undirected graph has n stations. Count the stations reachable from station 1, including station 1 itself.ApplyNot started
  2. 2Minimum hopsFind the minimum number of edges from station 1 to every vertex of an undirected graph. Print -1 for unreachable vertices.ConnectNot started
  3. 3Open regionsCount connected regions of free cells in a grid. Cells connect only through a shared side, not diagonally.ReasonNot started
  4. 4Two compatible groupsDecide whether the vertices of an undirected graph can be labeled A or B so that every edge joins different labels.StretchNot started

Read the lesson