{"problem":{"name":"Attraction on Tree","description":{"content":"You are given a tree with $N$ vertices numbered $1$ to $N$. The $i$\\-th edge connects two vertices $a_i$ and $b_i$ $(1\\leq i\\leq N-1)$. Initially, a piece is placed at vertex $1$. You will perform the","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"arc152_f"},"statements":[{"statement_type":"Markdown","content":"You are given a tree with $N$ vertices numbered $1$ to $N$. The $i$\\-th edge connects two vertices $a_i$ and $b_i$ $(1\\leq i\\leq N-1)$.\nInitially, a piece is placed at vertex $1$. You will perform the following operation exactly $N$ times.\n\n*   Choose a vertex that is not occupied by the piece at that moment and is never chosen in the previous operations, and move the piece one vertex toward the chosen vertex.\n\nA way to perform the operation $N$ times is called a _good procedure_ if the piece ends up at vertex $N$. Additionally, a good procedure is called an _ideal procedure_ if the number of vertices visited by the piece at least once during the procedure (including vertices $1$ and $N$) is the minimum possible.\nFind the number of vertices visited by the piece at least once during an ideal procedure. If there is no good procedure, print `-1` instead.\n\n## Constraints\n\n*   $2 \\leq N \\leq 2 \\times 10^5$\n*   $1 \\leq a_i,b_i \\leq N$\n*   All values in the input are integers.\n*   The given graph is a tree.\n\n## Input\n\nThe input is given from Standard Input in the following format:\n\n$N$\n$a_1$ $b_1$\n$a_2$ $b_2$\n$\\vdots$ \n$a_{N-1}$ $b_{N-1}$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"arc152_f","tags":[],"sample_group":[["4\n1 2\n2 4\n3 4","3\n\nIf you choose vertices $3$, $1$, $2$, $4$ in this order, the piece will go along the path $1$ → $2$ → $1$ → $2$ → $4$. This is an ideal procedure."],["6\n1 6\n2 6\n2 3\n3 4\n4 5","\\-1\n\nThere is no good procedure."],["14\n1 2\n1 3\n3 4\n3 5\n5 6\n6 7\n5 8\n8 9\n8 14\n14 10\n10 11\n14 12\n12 13","5"]],"created_at":"2026-03-03 11:01:13"}}