Skip to content
Back to libraryPart 4 · Advanced topics

4.1Trees

Before you start

It helps to have read 3.1 Graph search: BFS and DFS and 3.4 Dynamic programming I. Overall level: Advanced.

Practice: Trees

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. 1Subtree sizesRoot an undirected tree at vertex 1. For each vertex print the number of vertices in its subtree, including itself.ApplyNot started
  2. 2Subtree rewardsEach vertex has an integer reward. Root the tree at 1 and print the total reward in each vertex's subtree, including itself.ConnectNot started
  3. 3Tree diameterFind the greatest distance between two vertices in an unweighted tree. Distance means number of edges.ReasonNot started
  4. 4Farthest from each vertexFor every vertex of an unweighted tree, print its maximum distance to any vertex.StretchNot started

Read the lesson