Logo
(追記) (追記ここまで)

34461번 - Traveling Salesman Problem 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB20161386.667%

문제

There are $N$ cities numbered from 1ドル$ to $N,ドル the $i$-th of which is at coordinates $(x_i, y_i)$.

Busy Beaver wants to start at city 1ドル,ドル visit every city exactly once, and return to city 1ドル$.

To go from city $i$ to city $j,ドル it takes $|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 $T$ (1ドル \leq T \leq 10^4$) --- the number of test cases.

The first line of each test case contains a single integer $N$ (2ドル \leq N \leq 2 \cdot 10^5$) --- the number of cities.

The $i$-th of the next $N$ lines of each test case contains two integers $x_i$ and $y_i$ ($-10^9 \leq x_i, y_i \leq 10^9$) --- the coordinates of the $i$-th city.

The sum of $N$ across all test cases does not exceed 2ドル \cdot 10^5$.

출력

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

제한

예제 입력 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

예제 출력 1

10
14
8

노트

In the first test case, we can take the path 1ドル \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=10$ seconds.

출처

University > MIT > M(IT)^2 > M(IT)^2 Winter 2025 Tournament > Beginner Round 3번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /