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
| #include<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> PII;
const int INF = 1e9 + 7, MAXN = 2e5 + 10, mod = 998244353;
struct Point {
ll x, y;
Point() {};
Point(int x, int y) : x(x), y(y) {}
};
ll crs(Point a, Point b) {
return a.x * b.y - a.y * b.x;
}
typedef vector<Point> Points;
void solve() {
int n, m;
cin >> n >> m;
Points ps1(n);
Points ps2(m);
for(auto &[x, y] : ps1) {
cin >> x >> y;
}
for(auto &[x, y] : ps2) {
cin >> x >> y;
}
auto check = [&](Point a, Point b) {
bool ok = true;
for(Point p : ps2) {
Point x = Point(b.x - a.x, b.y - a.y);
Point y = Point(p.x - a.x, p.y - a.y);
if(!(ok = crs(x, y) > 0)) {
break;
}
}
return ok;
};
struct Edge {
int from, to;
};
vector<vector<int>> dis(n, vector<int> (n, INF));
for(int i = 0; i < n; i ++) {
for(int j = 0; j < n; j ++) {
if(i != j && check(ps1[i], ps1[j])) {
dis[i][j] = min(dis[i][j], 1);
}
}
}
for(int i = 0; i < n; i ++) {
dis[i][i] = INF;
}
for(int k = 0; k < n; k ++) {
for(int i = 0; i < n; i ++) {
for(int j = 0; j < n; j ++) {
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
}
}
int res = INF;
for(int i = 0; i < n; i ++) {
for(int j = i; j < n; j ++) {
res = min(res, dis[i][j] + dis[j][i]);
}
}
if(res >= INF) {
res = -1;
}
cout << res << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int _ = 1;
cin >> _;
while(_ --) {
solve();
}
}
|