Planet Tunnels
Time limit1sMemory limit128 MB
Given N 3D points with edge cost equal to the minimum coordinate-axis distance between two points, find the minimum spanning tree cost connecting all of them efficiently.
- Level
Hard8 of 10
- Topics
- Minimum spanning tree, Sorting, Union-find
- Solved
- No attempts yet
Problem
In the year 2040, Minhyeok builds his own kingdom in space consisting of planets. To rule them efficiently he wants to build tunnels connecting the planets.
Each planet is a point in 3D space. The cost of a tunnel between planets and is .
Minhyeok wants to build exactly tunnels so that all planets are connected. Write a program that computes the minimum total cost to connect all planets with tunnels.
Input
The first line contains the number of planets (). Each of the next lines contains the , , and coordinates of a planet. Each coordinate is an integer between and . No two planets share the same position.
Output
Print the minimum total cost to connect all planets with tunnels.