版本比较
二分图浅析(中文版)
正文
增加 17 行删除 17 行
210 行未改动全部展开211212213214215215216217218218219220220221222222223224224225226226227228229230260 行未改动全部展开49149249349449549549649749849966 行未改动56656756856957057057157257357476 行未改动65165265365465565565665765865966 行未改动72672772872973073073173273373481 行未改动81681781881982082082182282382475 行未改动90090190290390490490590690790840 行未改动94995095195295395395495595695795795895996096129 行未改动991992993994995995996997998999173 行未改动全部展开117311741175117611771177117811791180118192 行未改动127412751276127712781278127912801281128241 行未改动210 行未改动全部展开
- **第二步**:匹配 - 将1与5匹配
 - 将2与6匹配

- 将3与5匹配,然而我们发现:5已经和1匹配,那么我们是 _遵循先入_ 为主,还是 _强行入住_ 呢?
**当然要匹配**,我们将1与5取消匹配,让1再去和其他的点匹配,若成,3和5匹配;不成,3和其他顶点匹配。1与7匹配成功!3与5匹配成功!**如图:**

- **第三步**:输出
至此,我们~~可爱的~~匈牙利算法就结束了,上图最大匹配为**3**。
260 行未改动全部展开***## 例题:- [$\small\color{#ff4081}\texttt{P1129矩阵游戏}$](https://www.luogu.org/problemnew/show/P1129) - $code$:
```cpp#include <cstdio>#include <cstring>using namespace std;66 行未改动}```- [$\small\color{#ff4081}\texttt{P2055假期的宿舍}$](https://www.luogu.org/problemnew/show/P2055) - $code:$
```cpp#include <cstdio>#include <cstring>using namespace std;76 行未改动}```- [$\small\color{#ff4081}\texttt{P1402 酒店之王}$](https://www.luogu.org/problemnew/show/P1402) - $code:$
```cpp#include <cstdio>#include <cstring>using namespace std;66 行未改动}```- [$\small\color{#ff4081}\texttt{T67865 小xzy的象棋}$](https://www.luogu.org/problemnew/show/T67865) - $code:$
```cpp#include <cstdio>#include <cstring>using namespace std;81 行未改动
### 匈牙利算法建图一般有如下几组情况:- 行列匹配法 如[$\small\color{#ff4081}\texttt{P1129矩阵游戏}$](https://www.luogu.org/problemnew/show/P1129)- 黑白染色法 如[$\small\color{#ff4081}\texttt{Chessboard}$](http://poj.org/problem?id=2446)- 反建法 - 反建法- 拆点法 如[$\small\color{#ff4081}\texttt{P2764 最小路径覆盖问题}$](https://www.luogu.org/problemnew/show/P2764)- 一行变多行,一列变多列 如[$\small\color{#ff4081}\texttt{T67865 小xzy的象棋}$](https://www.luogu.org/problemnew/show/T67865)- 混合法 如[$\small\color{#ff4081}\texttt{P1402 酒店之王}$](https://www.luogu.org/problemnew/show/P1402)
75 行未改动 cnt=0; memset(map,0,sizeof(map)); memset(c,1,sizeof(c)); for(int i=1;i<=k;i++) { { scanf("%d%d",&x,&y); c[y][x]=0; } for(int i=1;i<=n;i++)40 行未改动{ int v,nx;}set[MAXM];int head[MAXN];int chk[MAXN],match[MAXN]; int chk[MAXN],match[MAXN];
inline void Addedge(int u,int v){ id++;set[id].v=v;set[id].nx=head[u]; id++;set[id].v=v;set[id].nx=head[u]; head[u]=id;}
inline void init()29 行未改动}
int main(){ init(); init(); int ans=n; for (int i=1;i<=n;i++) { now++;173 行未改动全部展开 { match[i]=ex_girl[i]=ex_boy[i]=0; for(int j=1;j<=n;j++) if(rela[i][j]>ex_girl[i])ex_girl[i]=rela[i][j]; } } for(int i=1;i<=n;i++) { now=0; for(int j=1;j<=n;j++)92 行未改动 { match[i]=ex_girl[i]=ex_boy[i]=0; for(int j=1;j<=n;j++) if(rela[i][j]>ex_girl[i])ex_girl[i]=rela[i][j]; } } for(int i=1;i<=n;i++) { now=0; for(int j=1;j<=n;j++)41 行未改动