Connecting Cities by Grid — Solution & Editorial
Prim's algorithm on the complete Manhattan-distance graph is O(N²), sufficient here. (The specialized Manhattan-MST reduces the edge set to O(N) using 4-quadrant sweeps for N = 105.)
Complexity: O(N2)
Watch out: Total cost reaches ~109.