AtCoder Regular Contest 179
D
Portable Gate
AtCoder
⌀ 2717
原题
← CE →
翻译中…

Problem Statement

翻译中…

You are given a tree with $N$ vertices numbered $1, 2, \dots, N$. The $i$-th edge connects vertices $u_i$ and $v_i$ bidirectionally.

翻译中…

Initially, all vertices are painted white.

翻译中…

To efficiently visit all vertices of this tree, Alice has invented a magical gate. She uses one piece and one gate to travel according to the following procedure.

翻译中…

First, she chooses a vertex and places both the piece and the gate on that vertex. Then, she repeatedly performs the following operations until all vertices are painted black.

翻译中…
  • Choose one of the following actions:
  • Paint the vertex where the piece is placed black.
    • Choose a vertex adjacent to the vertex where the piece is placed and move the piece to that vertex. The cost of this action is $1$.
    • Move the piece to the vertex where the gate is placed.
    • Move the gate to the vertex where the piece is placed.
翻译中…

Note that only the second action incurs a cost.

翻译中…

It can be proved that it is possible to paint all vertices black in a finite number of operations. Find the minimum total cost required.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 2 \times 10^5$
  • $1 \leq u_i, v_i \leq N$
  • The given graph is a tree.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
u_1 v_1
\vdots
u_{N-1} v_{N-1}

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
4
1 2
1 3
1 4
Output #1
3
Here is an example of Alice's procedure. Let $(u, v)$ denote the state where the piece is at vertex $u$ and the gate is at vertex $v$. - Place the piece and the gate at vertex $4$. - The state is now $(4, 4)$. - Perform action $1$. - Vertex $4$ is painted black. - The state is now $(4, 4)$. - Perform action $2$ and move the piece to vertex $1$. - This costs $1$. - The state is now $(1, 4)$. - Perform action $1$. - Vertex $1$ is painted black. - Perform action $4$. - The state is now $(1, 1)$. - Perform action $2$ and move the piece to vertex $2$. - This costs $1$. - The state is now $(2, 1)$. - Perform action $1$. - Vertex $2$ is painted black. - Perform action $3$. - The state is now $(1, 1)$. - Perform action $2$ and move the piece to vertex $3$. - This costs $1$. - The state is now $(3, 1)$. - Perform action $1$. - Vertex $3$ is painted black. - All vertices are now painted black, so the procedure ends. The total cost of performing action $2$ is $3$, and there is no procedure with a smaller cost.
Input #2
10
1 7
7 10
10 8
8 3
8 4
10 9
9 6
9 5
7 2
Output #2
10
题目信息
题号
arc179_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。