Three lessons from this problem:
MST algorithms work on complete graphs if you generate edges on demand
Prim is better when generating all edges upfront is expensive in time or space
You can compute edge weights on the fly to save memory If you solved this, you understand how to apply MST to geometric problems. This pattern appears in many clustering and network design tasks. The on-demand edge generation is a useful technique.