Luogu 3386(二分图最大匹配)
生活随笔
收集整理的這篇文章主要介紹了
Luogu 3386(二分图最大匹配)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
傳送門
模板題。
新技能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; }總結
以上是生活随笔為你收集整理的Luogu 3386(二分图最大匹配)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 阿里云域名网站https申请,ssl续签
- 下一篇: Play Framework IV 依赖