| CAMA 2024 |
|---|
| Закончено |
Gridland is a mysterious world which exists inside of the Cartesian plane.
According to tradition, perhaps superstition, all the roads in Gridland must be made of linear segments parallel to the $$$x$$$ axis or the $$$y$$$ axis. The trains of Gridland have a very interesting property: they can only turn at most twice in one journey. This used to be an inconvenience for its citizens, who sometimes had to take more than one train in order to travel between two cities.
After a civil war broke out, the entire railway infrastructure of the country was destroyed. The new Minister of Transportation, Gustavo, has proposed an ambitious plan to build a new railway network that allows direct train travels between every city. However, Gustavo has to devise a budget to determine the project's feasibility. He needs your help to figure out the minimum total length of the new railway network.
The first line contains only an integer $$$t$$$ $$$(1 \le t \le 1000)$$$, the number of test cases.
The first line of each test case is an integer $$$n$$$ $$$(1 \le n \le 2 \cdot 10^5)$$$, the number of cities in Gridland.
The second line of each test case contains $$$n$$$ pairs of integers $$$-10^9 \le x_i, y_i \le 10^9$$$, where $$$x_i$$$ and $$$y_i$$$ are the $$$x$$$ and $$$y$$$ coordinates, respectively, of the $$$i$$$-th city.
It is guaranteed that the total sum of $$$n$$$ from all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print one integer, the minimum length of roads needed to connect all of the cities such that it is always possible to travel between any two of them with at most two turns.
2 9 -3 0 -2 -2 -1 1 -1 4 0 0 1 3 2 -1 3 2 3 3 3 0 0 0 1 0 3
19 3
| Название |
|---|


