#include <bits/stdc++.h>
using namespace std;
//-----pre_def----
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
#define fir(i, a, b) for (int i = (a); i <= (b); i++)
#define rif(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define init_h memset(h, -1, sizeof h), idx = 0;
#define lowbit(x) x &(-x)
//---------------
const int N = 1e3 + 10;
int n, a, b;
PII s[2];
PII d[N], aa[N], bb[N];
int diss, dis1[N], dis0[N];
int dist(int i, int j)
{
return abs(d[i].first - s[j].first) + abs(d[i].second - s[j].second);
}
struct two_SAT
{
int n; //未翻倍之前的点数
bool in_stack[N];
int id[N], stk[N], top, dfn[N], low[N], times, scc_cnt; //所在scc编号,栈,dfs序,最下能到哪个节点,时间戳,scc编号
int h[N], e[N * N], ne[N * N], idx;
void init(int _n)
{
n = _n;
init_h;
}
void over()
{
memset(id, 0, sizeof id);
memset(dfn, 0, sizeof dfn);
memset(low, 0, sizeof low);
memset(in_stack, 0, sizeof in_stack);
times = top = scc_cnt = 0;
init_h;
}
inline void add(int a, int b)
{
e[idx] = b;
ne[idx] = h[a];
h[a] = idx++;
}
inline void add_and(int x, int valx, int y, int valy) //如果x取valx,则y必须取valy
{
//x -> y or !x -> y or x -> !y or !x -> !y
add(x + valx * n, y + valy * n);
}
void add_or(int x, int valx, int y, int valy) //x取valx 或 y取valy
{
add(x + (!valx) * n, y + valy * n);
add(y + (!valy) * n, x + valx * n);
}
void add_one(int x, int valx)
{
add_or(x, valx, x, valx);
}
void tarjan(int u)
{
dfn[u] = low[u] = ++times;
stk[++top] = u, in_stack[u] = true;
for (int i = h[u]; ~i; i = ne[i])
{
int j = e[i];
if (!dfn[j])
{
tarjan(j);
low[u] = min(low[u], low[j]);
}
else if (in_stack[j])
{
low[u] = min(low[u], dfn[j]);
}
}
if (dfn[u] == low[u])
{
++scc_cnt;
int y;
do
{
y = stk[top--];
in_stack[y] = false;
id[y] = scc_cnt;
} while (y != u);
}
}
void tarjan()
{
fir(i, 1, n << 1) if (!dfn[i])
tarjan(i);
}
bool solve()
{
tarjan();
for (int i = 1; i <= n; i++)
if (id[i] == id[i + n])
return false;
return true;
}
bool check(int x)
{
fir(i, 1, a)
{
add_or(aa[i].first, 1, aa[i].second, 1);
add_or(aa[i].first, 0, aa[i].second, 0);
}
fir(i, 1, b)
{
add_and(bb[i].first, 1, bb[i].second, 1);
add_and(bb[i].first, 0, bb[i].second, 0);
add_and(bb[i].second, 1, bb[i].first, 1);
add_and(bb[i].second, 0, bb[i].first, 0);
// add_or(aa[i].first,0,aa[i].second,0);
}
fir(i, 1, n)
{
fir(j, i + 1, n)
{
if (dis0[i] + dis0[j] > x)
{
add_and(i, 0, j, 1);
add_and(j, 0, i, 1);
}
if (dis1[i] + dis1[j] > x)
{
add_and(i, 1, j, 0);
add_and(j, 1, i, 0);
}
if (dis1[i] + diss + dis0[j] > x)
{
add_and(i, 1, j, 1);
add_and(j, 0, i, 0);
}
if (dis0[i] + diss + dis1[j] > x)
{
add_and(i, 0, j, 0);
add_and(j, 1, i, 1);
}
}
}
return solve();
}
void func()
{
int l = 0, r = 15000000, ans = -1;
while (l <= r)
{
//cout << l << " " << r << endl;
int mid = l + r >> 1;
if (check(mid))
{
ans = mid;
r = mid - 1;
}
else
{
l = mid + 1;
}
over();
}
printf("%d\n", ans);
}
} t;
void init() {}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
int StartTime = clock();
#endif
while (scanf("%d%d%d", &n, &a, &b) != EOF)
{
t.init(n);
scanf("%d%d%d%d", &s[0].first, &s[0].second, &s[1].first, &s[1].second);
diss = (abs(s[0].first - s[1].first) + abs(s[0].second - s[1].second));
fir(i, 1, n)
{
scanf("%d%d", &d[i].first, &d[i].second);
dis0[i] = dist(i, 0);
dis1[i] = dist(i, 1);
}
fir(i, 1, a)
{
scanf("%d%d", &aa[i].first, &aa[i].second);
}
fir(i, 1, b)
{
scanf("%d%d", &bb[i].first, &bb[i].second);
}
t.func();
}
#ifndef ONLINE_JUDGE
printf("Run_Time = %d ms\n", clock() - StartTime);
#endif
return 0;
}
08-22