# 题目大意

n * n矩阵有K个点，第i个点的坐标为(Xi，Yi)。每次可以把某行或者某列删掉。问至少需要多少次可以把K个点都删掉。
( n500 n ≤ 500 $n\leq 500$)

# 题解

## code

#include<bits/stdc++.h>
using namespace std;
int num=0;char c=' ';bool flag=true;
for(;c>'9'||c<'0';c=getchar())
if(c=='-')
flag=false;
for(;c>='0'&&c<='9';num=(num<<3)+(num<<1)+c-48,c=getchar());
return flag ? num : -num;
}
namespace graph{
const int INF=0x7fffffff;
const int maxn=1000;
struct node{
int y,val,next;
}a[maxn*maxn];
void insert(int x,int y,int v){
a[top].y=y;
a[top].val=v;
}
int n,k,s,t;
void init(){
s=0;t=2*n+1;
for(int i=1;i<=k;i++){
insert(x,y,1);
insert(y,x,0);
}
for(int i=1;i<=n;i++){
insert(0,i,1);
insert(i,0,0);
insert(i+n,t,1);
insert(t,i+n,0);
}
}
}using namespace graph;
namespace max_flow{
int vis[maxn],cur[maxn];
bool bfs(){
memset(vis,0,sizeof vis);
queue<int>q;
q.push(s);
vis[s]=1;
while(!q.empty()){
int u=q.front();
q.pop();
int v=a[i].y;
if(vis[v]||a[i].val==0)continue;
vis[v]=vis[u]+1;
q.push(v);
if(v==t)return true;
}
}
return false;
}
int dfs(int x,int flow){
if(x==t)return flow;
for(int &i=cur[x];i+1;i=a[i].next){
int y=a[i].y;
if(vis[y]!=vis[x]+1||a[i].val==0)continue;
int k=dfs(y,min(a[i].val,flow));
if(k){
a[i].val-=k;
a[i^1].val+=k;
return k;
}
}
return 0;
}
}using namespace max_flow;
int main(){
init();
int ans=0;
while(bfs()){
for(int i=s;i<=t;i++)
while(int flow=dfs(s,INF))
ans+=flow;
}
printf("%d\n",ans);
return 0;
}

03-13 379
02-03 203
08-19 1186
08-24 55
01-29 75
08-05 213