P2212 [USACO14MAR] Watering the Fields S

Description

Due to a lack of rain, Farmer John wants to build an irrigation system to send water between his N fields (1

Input Format

* Line 1: The integers N and C. * Lines 2..1+N: Line i+1 contains the integers xi and yi.

Output Format

* Line 1: The minimum cost of a network of pipes connecting the fields, or -1 if no such network can be built.

Explanation/Hint

INPUT DETAILS: There are 3 fields, at locations (0,2), (5,0), and (4,3). The contractor will only install pipes of cost at least 11. OUTPUT DETAILS: FJ cannot build a pipe between the fields at (4,3) and (5,0), since its cost would be only 10. He therefore builds a pipe between (0,2) and (5,0) at cost 29, and a pipe between (0,2) and (4,3) at cost 17. Source: USACO 2014 March Contest, Silver