#P2076. Manhattan Minimum Spanning Tree
Manhattan Minimum Spanning Tree
Manhattan Minimum Spanning Tree
You are given n points on the plane: \((x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)\).
Consider a complete graph with n nodes where for every pair of nodes \(u\) and \(v\) (with \(1 \le u, v \le n, u \ne v\)), there is an edge connecting them with weight \[ |x_u - x_v| + |y_u - y_v| \] which is the Manhattan distance between the two points.
Your task is to find the total weight of the Minimum Spanning Tree (MST) of this graph.
Note: When \(n = 1\), the MST weight is 0.
inputFormat
The first line contains a single integer n, the number of points.
Each of the following n lines contains two integers \(x_i\) and \(y_i\), representing the coordinates of the \(i\)th point.
Constraints: It is guaranteed that the input is valid and fits in the available memory.
outputFormat
Output a single integer, which is the total weight of the minimum spanning tree of the complete graph defined above.
sample
4
0 0
0 1
1 0
1 1
3
</p>