Description
给定
n
个
求删除最小的圆的数量,使得从
(0,ys)
到
(L,ye)
(0≤ys,ye≤W)
存在一条路径不与任何依旧存在的圆相交或相切。
Solution
刚开始傻逼了,以为是边连通度。。直接跑了最大流。。
把下边界记作点
S
,下边界记作
若两个圆相切或相交就连边。
其实要求的是一个叫作点连通度的东西。
根据
Menger's theorem
可以把点
u
拆成入点和出点
- cap(ui,uo)=1
- cap(uo,vi)=(vo,ui)=+∞
然后根据最大流-最小割定理跑一边最大流就可以啦。
最开始写了一个枚举源汇点的东西。
其实这道题
S
和
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const int INF = 1 << 28;
typedef pair<int, int> Pairs;
struct Point {
int x, y;
inline friend bool operator <(const Point &a, const Point &b) {
return a.y == b.y ? a.x < b.x : a.y < b.y;
}
};
struct edge {
int to, next, cap;
edge(int t = 0, int n = 0, int c = 0):to(t), next(n), cap(c) {}
};
Point p[N];
edge G[N * N << 1];
int n, L, W, S, T, Gcnt, clc, ans, e, pos, mn;
int head[N], deg[N];
int vis[N], d[N], cur[N];
queue<int> Q;
inline void AddEdge(int from, int to, int cap) {
G[++Gcnt] = edge(to, head[from], cap); head[from] = Gcnt;
G[++Gcnt] = edge(from, head[to], 0); head[to] = Gcnt;
}
inline void Add(int from, int to, int cap) {
AddEdge(from + e, to, cap);
AddEdge(to + e, from, cap);
++deg[from]; ++deg[to];
}
inline long long Dist2(Point &a, Point &b) {
return (long long)(a.x - b.x) * (a.x - b.x) + (long long)(a.y - b.y) * (a.y - b.y);
}
bool bfs(int S, int T) {
++clc; d[S] = 0; d[T] = INF;
Q.push(S); vis[S] = clc; int x, to;
while (!Q.empty()) {
x = Q.front(); Q.pop();
for (int i = head[x]; i; i = G[i].next) {
to = G[i].to;
if (G[i].cap && vis[to] != clc) {
Q.push(to); vis[to] = clc;
d[to] = d[x] + 1;
}
}
}
return d[T] != INF;
}
int dfs(int u, int a) {
if (a == 0 || u == T) return a;
int flow = 0, f;
for (int &i = cur[u]; i; i = G[i].next) {
edge &e = G[i];
if (d[e.to] == d[u] + 1 && e.cap
&& (f = dfs(e.to, min(a, e.cap))) > 0) {
flow += f; e.cap -= f;
G[i ^ 1].cap += f; a -= f;
if (!a) break;
}
}
return flow;
}
inline int MaxFlow(int S, int T) {
int flow = 0;
while (bfs(S, T)) {
for (int i = 1; i <= 1000; i++) cur[i] = head[i];
flow += dfs(S, INF);
}
return flow;
}
int main(void) {
freopen("escape.in", "r", stdin);
freopen("escape.out", "w", stdout);
scanf("%d %d %d", &L, &W, &n);
S = n + 1; T = n + 2;
Gcnt = 1; e = n + 2;
for (int i = 1; i <= n; i++) {
scanf("%d %d", &p[i].x, &p[i].y);
if (p[i].y <= 100) Add(S, i, INF);
if (p[i].y + 100 >= W) Add(i, T, INF);
}
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
if (40000ll >= Dist2(p[i], p[j]))
Add(i, j, INF);
for (int i = 1; i <= e; i++)
AddEdge(i, i + e, 1);
ans = MaxFlow(S + e, T);
printf("%d\n", ans);
return 0;
}