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.
- 1Subtree sizesAn undirected tree has n vertices, numbered 1 to n, and is rooted at vertex 1. Print the number of vertices in each vertex's subtree, including the vertex itself.ApplyNot started
- 2Subtree rewardsA tree has n vertices, numbered 1 to n, and is rooted at vertex 1. Vertex i has an integer reward ai. Print the total reward in each vertex's subtree, including the vertex itself.ConnectNot started
- 3Tree diameterAn unweighted tree has n vertices, numbered 1 to n. Find the greatest distance between two vertices, where distance is the number of edges on the path between them.ReasonNot started
- 4Farthest from each vertexAn unweighted tree has n vertices, numbered 1 to n. Print, for every vertex, its greatest distance to any vertex of the tree, measured in edges.StretchNot started