【洛谷2756】飞行员配对方案问题(二分图匹配,网络流24题)

前言

网络流24题还是要做完吧!

题解

这是一道模板题,这里主要讲一下怎么匈牙利二分图匹配:

  1. 对于左边的枚举每一次选的左边的人
  2. 对于右边与他有连边的那么就是能换则换,不然就不换
  3. 最后统计出来的就是\(ans\)

差不多就是这样子了吧。

#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi(){
    int f=1,sum=0;char ch=getchar();
    while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
    return f*sum;
}
const int N=1010;
int front[N],nxt[N<<1],to[N<<1],cnt;
void Add(int u,int v){
    to[++cnt]=v;nxt[cnt]=front[u];front[u]=cnt;
}
bool used[N];
int b[N],ans,a[N],n,m,u,v;
bool dfs(int);
struct node{
    int l,r;
    bool operator<(const node b)const{
        return l

转载于:https://www.cnblogs.com/mle-world/p/10251275.html

你可能感兴趣的:(【洛谷2756】飞行员配对方案问题(二分图匹配,网络流24题))