NOI Contest Archive

Archive / 2020 / Final Round — Day 1

Teleporting Bridges

Medium · National Olympiad in Informatics Sri Lanka 2020 - Day 1

There are M known worlds in a two-dimensional universe. Each world contains one or more cities, and each city will be located in one of those M worlds. A city is a point in the 2D universe that is represented by an integer coordinate (x,y). No more than 1 city will share the same coordinate. There are N cities in the universe and some of those cities are also called Megacities. Each world has at least one Megacity.

The distance between two cities is the euclidean distance (the distance of the straight line) between the two points. All the cities in the universe are laid out satisfying the following conditions:

As the founder of The Porting Company, your goal is to provide teleporting infrastructure so that people can teleport between any two cities in the universe. You achieve that by building a set of teleporting bridges. A teleporting bridge can be constructed between any two cities in the same world, or between any two Megacities.

People can teleport from city S to city E if at least one of the following conditions are satisfied:

The cost of constructing a teleporting bridge between two cities is the square of the distance between the two cities. i.e. if the distance is d, then the cost id d2.

Your task is to derive the minimum total cost to construct teleporting bridges so that people can teleport between any pair of cities in the universe.

Input Format

The first line contains an integer M, the number of worlds.

Each pair of next 2M lines will contain information about M worlds.

Output Format

The minimum total cost to construct teleporting bridges.

Constraints

At least 25% of test cases will have only 1 world.
At least 25% of cases will have only 1 city in each world.

Limits

Sample Input 0

2
1 0 0
2 1 0 -1 0
2 0 100000 0 100002
0

Sample Output 0

10000000006