Light Up the Bulbs
Practice
4.1 (14 votes)
Disjoint data structures
Data structures
Basics of disjoint data structures
Problem
88% Success 2216 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Demon has a warehouse and he wants to light up the warehouse by lighting N bulbs on the ceiling. Consider the ceiling as a coordinate axis and Demon knows the X - Y coordinates of the bulbs that need to be put at the ceiling. Now the bulbs need to be connected with each other using wires. Demon wants to know the minimum sum of the square of the length of wires required to connect the bulbs.

Note: If bulb A and B are connected, bulb B and bulb C are connected, then bulb A and C are also connected.

Input Format:
The first line contains an integer N - the number of bulbs needed to light up the warehouse. The next N lines contain two space-separated integers x and y - representing the coordinates of the bulb.

Output Format:
Output the minimum length of wire required to connect the light bulbs.

Constraints:
\(1 \leq N \leq 1000\)
\(0 \leq x, y \leq 1000\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
8 votes
Tags:
Data StructuresDisjoint setMediumString Manipulation
Points:30
55 votes
Tags:
ApprovedData StructuresDisjoint setMediumOpen
Points:30
5 votes
Tags:
Data StructuresDisjoint Data StructuresBasics of Disjoint Data Structures