matrix67大神的证明楞是看不懂。。
简单来说就是跑匈牙利的时候将不能成功匹配的点做标记,在一侧(n+1~2n部分)取没有标记的在另一侧取有标记的即形成最小点覆盖。。
然后这题要用最小的行列覆盖点,将点化成边,行列化成点就符合最小点覆盖的定义了,直接跑二分图。。
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━━━━━━━━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1LL<<(x))
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 1005
#define nm 10005
#define N 1000005
#define M(x,y) x=max(x,y)
const double pi=acos(-1);
const ll inf=19260817;
using namespace std;
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}
struct edge{int t;edge*next;}e[nm],*h[NM],*o=e;
void add(int x,int y){o->t=y;o->next=h[x];h[x]=o++;}
int n,m,_x,_y,match[NM],v[NM],s;
bool dfs(int x){
link(x)if(v[j->t]!=_x){
v[j->t]=_x;
if(!match[j->t]||dfs(match[j->t])){match[j->t]=x;return true;}
}
return false;
}
int main(){
n=read();m=read();
inc(i,1,m){_x=read();_y=read();add(_x,_y+n);}
inc(i,1,n)if(dfs(_x=i))s++;
return 0*printf("%d\n",s);
}
Asteroids
Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (1 <= K <= 10,000), which are conveniently located at the lattice points of the grid. Input * Line 1: Two integers N and K, separated by a single space. Output * Line 1: The integer representing the minimum number of times Bessie must shoot. Sample Input Sample Output Hint INPUT DETAILS: Source |