4 1 2 1 3 1 4
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.10 1 7 7 10 10 8 8 3 8 4 10 9 9 6 9 5 7 2
10
{
"problem": {
"name": "Portable Gate",
"description": {
"content": "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 al",
"description_type": "Markdown"
},
"platform": "AtCoder",
"limit": {
"time_limit": 2000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "arc179_d"
},
"statements": [
{
"statement_type": "Markdown",
"content": "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.\nInitially, all vertices are painted white.\nTo efficiently visit al...",
"is_translate": false,
"language": "English"
}
]
}