$Cost = (v_1 +(v_1+ vertex_d=1))+[\{v_1+(v_1+vertex_d=\color{Red}2)\}+\{v_2+(v_2+vertex_d=\color{Red}2)\}+\{v_3+(v_3+vertex_d=\color{Red}2)\}+\{v_4+(v_4+vertex_d=\color{Red}2)\}+......+\{v_{n-2}+(v_{n-2}+vertex_d=\color{Red}2)\}]$
$= (1 +(1+1))+[\{1+(1+\color{Red}2)\}+\{2+(2+\color{Red}2)\}+\{3+(3+\color{Red}2)\}+\{4+(4+\color{Red}2)\}+......+\{(n-2)+((n-2)+\color{Red}2)\}]$
$= 3+ [2*\{1+2+3+4+....+(n-2)\} + \color{Red}2*(n-2)] $
$= 3 + 2*[(n-2)(n-1)/2] + \color{Red}2*(n-2)$
$= 3 + (n-2)[n-1+2]$
$= n^2 -n +1$
where, $vertex_d$ = distance from current vertex
$Explanation:$
Here with the given conditions, you have to pick "ALL THE EDGES" from least labelled vertex (as they will be the one with least weights) such that you don't end up in a cycle.
Hence, from vertex $v_1$ possible edges are $v_1$$v_{2(1+1)}$ and $v_1$$v_{3(1+2)}$, from vertex $v_2$ edges are $v_2$$v_3$ and $v_2$$v_4$ but since vertex $v_3$ is already covered by edge $v_1$$v_3$ you need not pick $v_2$$v_3$. You will soon realize that vertex only with distance 2 from current vertex are taken (except for vertex $v_1$ which has the base case edge $v_1v_2$).The last term in the series will be for $v_{n-2}$ as it will cover the last vertex $v_n$.