A. In the graph start applying Kruskal algorithm. So, we select all edges of cost $1$ first.

For each $y = i$, there will be $n-1$ unit length path. Total cost = $n(n-1)$

Then we can join these $n$ lines by one vertical line whose length is $n-1$.

Total:

$$n(n-1) + (n-1) = (n-1)\cdot (n+1) = n^2 -1$$

B. We can apply Kruskal's algorithm by taking maximum weight edge (ref). Maximum weight edge here is $\sqrt 2$ as we are taking Euclidean distance as mentioned in question.

All diagonals will sum to:

$$\sqrt{2} (n-1) +2 \Bigl ( \sqrt{2} (n-2) + \sqrt{2} (n-3)+ \dots + \sqrt{2} \Bigr ) \\= \sqrt{2} (n-1) +\sqrt{2}. (n-1). (n-2) \\= \sqrt{2}. (n-1)^2$$

(One main diagonal and $(n-1)$ diagonals on either side of it).

Now, we can no more add any edge of weight $\sqrt 2$ without forming a cycle.

So, we take $2(n-1)$ edges of weight $1$ to interconnect these diagonals

$= \sqrt{2} (n -1)^2 + 2(n-1) \\= \sqrt{2} \cdot (n-1) \cdot (n-1+\sqrt 2)$