Traveling Salesman Problem

시간 제한1초메모리 제한256 MB

요약
이동 시간이 |dx + dy|일 때, 1번 도시에서 출발해 모든 도시를 한 번씩 방문하고 돌아오는 최소 시간을 구한다.
난이도

어려움10점 중 8점

유형
기하, 수학, 정렬, 그리디
정답자
아직 제출이 없습니다

문제

There are NN cities numbered from 11 to NN, the ii-th of which is at coordinates (x_i,y_i)(x\_i, y\_i).

Busy Beaver wants to start at city 11, visit every city exactly once, and return to city 11.

To go from city ii to city jj, it takes ∣x_i−x_j+y_i−y_j∣|x\_i - x\_j + y\_i - y\_j| seconds. Find the minimum number of seconds for Busy Beaver to complete his trip.

입력

The first line contains a single integer TT (1≤T≤1041 \leq T \leq 10^4) --- the number of test cases.

The first line of each test case contains a single integer NN (2≤N≤2⋅1052 \leq N \leq 2 \cdot 10^5) --- the number of cities.

The ii-th of the next NN lines of each test case contains two integers x_ix\_i and y_iy\_i (−109≤x_i,y_i≤109-10^9 \leq x\_i, y\_i \leq 10^9) --- the coordinates of the ii-th city.

The sum of NN across all test cases does not exceed 2⋅1052 \cdot 10^5.

출력

For each test case, output a single integer --- the minimum number of seconds needed for Busy Beaver to complete his trip.

힌트

In the first test case, we can take the path 1→3,seconds3→1,second4→1,second5→3,seconds2→2,seconds11 \xrightarrow{3\\,\text{seconds}} 3 \xrightarrow{1\\,\text{second}} 4 \xrightarrow{1\\,\text{second}} 5 \xrightarrow{3\\,\text{seconds}} 2 \xrightarrow{2\\,\text{seconds}} 1 which takes 3+1+1+3+2=103+1+1+3+2=10 seconds.

예제1

  1. 예제 1

    입력
    3
    5
    0 0
    -2 0
    1 2
    -1 3
    0 1
    3
    0 0
    1 4
    3 4
    2
    -1 9
    8 -4
    
    예상 출력
    10
    14
    8