Make Paths
Practice
4.4 (5 votes)
Algorithms
Approved
Data structures
Disjoint set
Hard
Open
Problem
36% Success 2955 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Walter White and Jesse Pinkman have now established their bases at different places.
Now they want to form a network, that is, they want that all their bases should be reachable from every base.
One base is reachable from other base if there is a path of tunnels connecting bases.
Bases are suppose based on a 2-D plane having integer coordinates.
Cost of building tunnels between two bases are coordinates (x1,y1) and (x2,y2) is min{ |x1-x2|, |y1-y2| }.
What is the minimum cost such that a network is formed.
Input:
First line contains N, the number of bases.
Each of the next N lines contain two integers xi and yi.
Output:
Print the minimum cost of building the network.
Constraints:
1 ≤ N ≤ 100000
-109 ≤ xi,yi ≤ 109
Submissions
Please login to view your submissions
Similar Problems
Points:50
41 votes
Tags:
ApprovedData StructuresDisjoint setHardImplementationOpen
Points:50
6 votes
Tags:
Data StructuresDisjoint Data StructuresDisjoint SetDisjoint setHard
Points:50
1 votes
Tags:
Data StructuresDisjoint Data StructuresDisjoint SetHard
Editorial