Score : $600$ points
We have a tree with $N$ vertices and $N-1$ edges, respectively numbered $1, 2,\cdots, N$ and $1, 2, \cdots, N-1$. Edge $i$ connects Vertex $u_i$ and $v_i$.
For integers $L, R$ ($1 \leq L \leq R \leq N$), let us define a function $f(L, R)$ as follows:
Compute $\sum_{L=1}^{N} \sum_{R=L}^{N} f(L, R)$.
Input is given from Standard Input in the following format:
$N$ $u_1$ $v_1$ $u_2$ $v_2$ $:$ $u_{N-1}$ $v_{N-1}$
Print $\sum_{L=1}^{N} \sum_{R=L}^{N} f(L, R)$.
3 1 3 2 3
7
We have six possible pairs $(L, R)$ as follows:
The sum of these is $7$.
2 1 2
3
10 5 3 5 7 8 9 1 9 9 10 8 4 7 4 6 10 7 2
113