-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2D Traveling
116 lines (90 loc) · 2.34 KB
/
2D Traveling
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include<bits/stdc++.h>
using namespace std;
#include<cstring>
#include<cstdio>
#include<vector>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using indexed_set = tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long
#define pf push_front
#define pb push_back
#define ppf pop_front()
#define ppb pop_back()
#define in insert
#define mp make_pair
#define f first
#define sd second
#define all(x) x.begin(), x.end()
#define mx(x) *max_element(all(x))
#define mn(x) *min_element(all(x))
#define cy cout<<"YES"<<'\n';
#define cn cout<<"NO"<<'\n';
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
//segment tree setup for maximum range
// void build(int ind,int low,int high,vector<int> &a,vi &seg){
// if(low==high){
// seg[ind]=a[low];
// return;
// }
// int mid=(low+high)/2;
// build(2*ind+1,low,mid,a,seg);
// build(2*ind+2,mid+1,high,a,seg);
// seg[ind]=max(seg[2*ind+1],seg[2*ind+2]);
// }
// ///
// int query(int ind,int low,int high,int l,int r,vi &seg){
// if(low>=l && high<=r){
// return seg[ind];
// }
// if(high<l || low>r) return INT_MIN;
// int mid=(low+high)/2;
// int left=query(2*ind+1,low,mid,l,r,seg);
// int right=query(2*ind+2,mid+1,high,l,r,seg);
// return max(left,right);
// }
///
// 48-57 -> 0-9
// 65-90 -> A-Z
// 97-122 -> a-z
// void setIO(string s) {
// freopen((s + ".in").c_str(), "r", stdin);
// freopen((s + ".out").c_str(), "w", stdout);
// }
void solve()
{
int n,k,a,b;
cin>>n>>k>>a>>b;
vpii arr(n+1);
rep(i,1,n+1)
{
int x,y;
cin>>x>>y;
arr[i]={x,y};
}
int dis1=1e12,dis2=1e12;
rep(i,1,k+1)
{
dis1=min(dis1,abs(arr[i].f-arr[a].f)+abs(arr[i].sd-arr[a].sd));
dis2=min(dis2,abs(arr[i].f-arr[b].f)+abs(arr[i].sd-arr[b].sd));
}
int dis3=abs(arr[a].f-arr[b].f)+abs(arr[a].sd-arr[b].sd);
cout<<min(dis1+dis2,dis3)<<'\n';
}
signed main(){
//setIO("problemname");
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--){
solve();
}
}