欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1869B.2D Traveling
2D Traveling
Piggy lives on an infinite plane with the Cartesian coordinate system on it.
There are cities on the plane, numbered from to , and the first cities are defined as major cities. The coordinates of the -th city are .
Piggy, as a well-experienced traveller, wants to have a relaxing trip after Zhongkao examination. Currently, he is in city , and he wants to travel to city by air. You can fly between any two cities, and you can visit several cities in any order while travelling, but the final destination must be city .
Because of active trade between major cities, it's possible to travel by plane between them for free. Formally, the price of an air ticket between two cities and is defined as follows:
$$$ f(i,j)= \begin{cases} 0, & \text{if cities }i \text{ and }j \text{ are both major cities} \\ |x_i-x_j|+|y_i-y_j|, & \text{otherwise} \end{cases}$$$Piggy doesn't want to save time, but he wants to save money. So you need to tell him the minimum value of the total cost of all air tickets if he can take any number of flights.
Input
The first line of input contains a single integer () — the number of test cases. The description of test cases follows.
The first line of each test case contains four integers , , and (, , , ) — the number of cities, the number of major cities and the numbers of the starting and the ending cities.
Then lines follow, the -th line contains two integers and () — the coordinates of the -th city. The first lines describe major cities. It is guaranteed that all coordinates are pairwise distinct.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, print a single integer — the minimum value of the total price of all air tickets.
Note
In the first test case:
The major cities are marked red.
The optimal way to choose the flights is: , which will cost . Note that the flight costs , because both city and are major cities.
In the second test case, since there are only cities, the only way is to take a flight from city to .
In the third test case, since city and are both major cities, Piggy can directly take a flight from city to , which costs .
In the fourth test case, Piggy can choose to take the following flights: , and the cost is .
Samples
5
6 2 3 5
0 0
1 -2
-2 1
-1 3
2 -2
-3 -3
2 0 1 2
-1000000000 -1000000000
1000000000 1000000000
7 5 4 2
154 147
-154 -147
123 456
20 23
43 20
998 244
353 100
3 1 3 1
0 10
1 20
2 30
4 3 2 4
0 0
-100 100
-1 -1
-1 0
4
4000000000
0
22
1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |