[Solution] Traveling Salesman Problem Codeforces Solution
You are living on an infinite plane with the Cartesian coordinate system on it. In one move you can go to any of the four adjacent points (left, right, up, down).
More formally, if you are standing at the point , you can:
- go left, and move to , or
- go right, and move to , or
- go up, and move to , or
- go down, and move to .
There are boxes on this plane. The -th box has coordinates . It is guaranteed that the boxes are either on the -axis or the -axis. That is, either or .
You can collect a box if you and the box are at the same point. Find the minimum number of moves you have to perform to collect all of these boxes if you
occupied
have to start and finish at the point .
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer () — the number of boxes.
The -th line of the following lines contains two integers and () — the coordinate of the -th box. It is guaranteed that either or .
Do note that the sum of over all test cases is not bounded.
For each test case output a single integer — the minimum number of moves required.
No comments:
Post a Comment