You are given a tree, that is, an undirected, connected graph with no cycles. You may choose any starting vertex, move around the tree step by step (from the current vertex to any adjacent vertex), visit every vertex at least once, and end your travel anywhere. What is the minimum number of steps to do so?
Input consists of several cases, each with the number of vertices of the tree, followed by pairs denoting an edge between and . Assume , that vertices are numbered between 1 and , and that the given edges indeed form a tree.
For every graph, print the minimum number of steps to visit the whole tree.
Author: Manuel Torres
Event: Vint-i-quatrè Concurs de Programació de la UPC -
Semifinal
Date: 2026-06-18
Generation: 2026-06-10T22:55:34.453Z
© Jutge.org, 2006–2026.
https://jutge.org