Yet another tree problem P91983


Statement
 

pdf   zip

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

Input consists of several cases, each with the number nn of vertices of the tree, followed by n1n - 1 pairs xx yy denoting an edge between xx and yy. Assume 2n1052 \le n \le 10^5, that vertices are numbered between 1 and nn, and that the given edges indeed form a tree.

Output

For every graph, print the minimum number of steps to visit the whole tree.

Public test cases
  • Input

    4
    3 2
    1 2
    3 4
    5
    5 1
    2 5
    4 5
    5 3
    

    Output

    3
    6
    
  • Information
    Author
    Manuel Torres
    Language
    English
    Official solutions
    C++
    User solutions
    C++