Luogu 3386(二分图最大匹配)
来源:互联网 发布:属性数据分析 编辑:程序博客网 时间:2024/05/29 09:34
传送门
模板题。
新技能get:存增广标记的cov数组如果使用int类型就不用每次memset(以前的版本在之前的博文中有过),可以大幅节约时间。
晚安~
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>using namespace std;const int N=1004;int n,m,eg;int head[N<<1],etot=0;struct EDGE {int v,nxt;}e[N*N];int cov[N<<1],lk[N<<1];inline int read() {int x=0;char c=getchar();while (c<'0'||c>'9') c=getchar();while (c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();return x;}inline void adde(int u,int v) {e[etot].nxt=head[u],e[etot].v=v,head[u]=etot++;e[etot].nxt=head[v],e[etot].v=u,head[v]=etot++;}bool dfs(int p,int id) {for (int i=head[p];~i;i=e[i].nxt) {int v=e[i].v;if (cov[v]^id) {cov[v]=id;if (lk[v]==-1||dfs(lk[v],id)) {lk[v]=p;return true;}}}return false;}int main() {//freopen("P3386.in","r",stdin);memset(head,-1,sizeof(head));n=read(),m=read(),eg=read();for (register int i=0;i<eg;++i) {int u=read(),v=read();if (u>n||v>m) continue;adde(u,v+n);}memset(lk,-1,sizeof(lk));int max_match(0);for (int i=1;i<=n;++i)if (dfs(i,i)) ++max_match;cout<<max_match<<endl;return 0;}
阅读全文
0 0
- Luogu 3386(二分图最大匹配)
- [luogu P2526][SHOI2001]小狗散步(二分图最大匹配)
- 二分图(最大匹配)
- 二分图最大匹配
- 二分图最大匹配 。
- 二分图最大匹配
- 二分图最大匹配
- 二分图最大匹配
- 二分图最大匹配
- 二分图 最大匹配
- 二分图最大匹配
- 二分图最大匹配
- 二分图最大匹配
- 二分图最大匹配
- 二分图最大匹配
- 二分图最大匹配
- 二分图最大匹配
- 二分图最大匹配
- kjgshjdksghdskjghdkfsghdsf
- MT7601u-STA模式(hi3518e)
- MFC基于select模型的套接字类之服务器(2)
- Python--FIFO,LIFO,ListC,Modules
- 产品经理的目标管理
- Luogu 3386(二分图最大匹配)
- 设计模式-依赖反转分析
- 第四周项目六C/C++链表:多项式求和
- Mahmoud and a Triangle 【codeforces】 【水题】
- Cookie&Session
- 文章标题
- Pycharm ++++ Django项目测试
- zookeeper实现分布式锁
- vim