3 5 1 2 2 3 2 4 4 5 8 8 6 7 2 2 1 3 7 5 6 1 6 4 3 7 7 1 5 2 1 2 6 5 4 1 5 3
1 2 0 1 3
1 2 2 3 1 4 0 0
1 2 2 0 3 0 4
In the first test case, for $P=(4,1,2,3,5)$, one can obtain $A(P)=(1,2,0,1,3)$ as follows:
* The vertex adjacent to vertex $1$ with the smallest written integer is vertex $2$. Append $P_2=1$ to the end of $A(P)$ and remove the edge connecting vertices $1$ and $2$.
* The vertex adjacent to vertex $2$ with the smallest written integer is vertex $3$. Append $P_3=2$ to the end of $A(P)$ and remove the edge connecting vertices $2$ and $3$.
* Vertex $3$ is an isolated vertex, so append $0$ to the end of $A(P)$.
* The vertex adjacent to vertex $4$ with the smallest written integer is vertex $2$. Append $P_2=1$ to the end of $A(P)$ and remove the edge connecting vertices $4$ and $2$.
* The vertex adjacent to vertex $5$ with the smallest written integer is vertex $4$. Append $P_4=3$ to the end of $A(P)$ and remove the edge connecting vertices $5$ and $4$.
It can be proved that this is the lexicographically smallest sequence among all possible $A(P)$.{
"problem": {
"name": "Edge Deletion 2",
"description": {
"content": "You are given a tree with $N$ vertices numbered $1$ to $N$. The $i$\\-th edge of the tree connects vertices $u_i$ and $v_i$ bidirectionally. For a permutation $P=(P_1,\\ldots,P_N)$ of $(1,2,\\ldots,N)$, ",
"description_type": "Markdown"
},
"platform": "AtCoder",
"limit": {
"time_limit": 2000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "arc170_f"
},
"statements": [
{
"statement_type": "Markdown",
"content": "You are given a tree with $N$ vertices numbered $1$ to $N$. The $i$\\-th edge of the tree connects vertices $u_i$ and $v_i$ bidirectionally.\nFor a permutation $P=(P_1,\\ldots,P_N)$ of $(1,2,\\ldots,N)$, ...",
"is_translate": false,
"language": "English"
}
]
}