5 3 4 4 5 2 5 1 5 3 4 1 1 2 5 3
4 6 3 Let us explain the first query. Since $d(1, 4) = 2$ and $d(1, 1) = 0$, we have $\min(d(1, 4), d(1, 1)) = 0$. Since $d(2, 4) = 2$ and $d(2, 1) = 2$, we have $\min(d(2, 4), d(2, 1)) = 2$. Since $d(3, 4) = 1$ and $d(3, 1) = 3$, we have $\min(d(3, 4), d(3, 1)) = 1$. Since $d(4, 4) = 0$ and $d(4, 1) = 2$, we have $\min(d(4, 4), d(4, 1)) = 0$. Since $d(5, 4) = 1$ and $d(5, 1) = 1$, we have $\min(d(5, 4), d(5, 1)) = 1$. $0 + 2 + 1 + 0 + 1 = 4$, so you should print $4$.
8 4 2 4 1 5 6 6 1 7 6 8 1 3 7 7 8 4 4 4 7 2 4 4 5 3 4 4 6 1
14 16 10 16 14 16 8
{
"problem": {
"name": "Ex - Sum of Min of Length",
"description": {
"content": "You are given a tree with $N$ vertices. The vertices are numbered $1$ to $N$, and the $i$\\-th edge connects vertex $A_i$ and vertex $B_i$. Let $d(x,y)$ denote the distance between vertex $x$ and $y$ i",
"description_type": "Markdown"
},
"platform": "AtCoder",
"limit": {
"time_limit": 3000,
"memory_limit": 262144
},
"difficulty": "None",
"is_remote": true,
"is_sync": true,
"sync_url": null,
"sign": "abc298_h"
},
"statements": [
{
"statement_type": "Markdown",
"content": "You are given a tree with $N$ vertices. The vertices are numbered $1$ to $N$, and the $i$\\-th edge connects vertex $A_i$ and vertex $B_i$.\nLet $d(x,y)$ denote the distance between vertex $x$ and $y$ i...",
"is_translate": false,
"language": "English"
}
]
}