标签:ini its return || hid one mes find font
简单二分图匹配,
#include<bits/stdc++.h> using namespace std; #define pb push_back const int N=1e3+5; int gp[N][N],match[N],vis[N]; int n,m; bool findpath(int u){ for(int i=m+1;i<=n+m;i++){ if(gp[u][i]&&!vis[i]){ vis[i]=1; if(!match[i]||findpath(match[i])){ match[i]=u; return 1; } } } return 0; } void init(){ memset(gp,0,sizeof gp); memset(match,0,sizeof match); } int main(){ init(); scanf("%d %d",&m,&n); int u,v; while(~scanf("%d %d",&u,&v)){ if(u+v<0)break; gp[u][v]=1; } vector<int>ans; for(int i=1;i<=m;i++){ memset(vis,0,sizeof vis); if(findpath(i))ans.pb(i); } for(int i=m+1;i<=n+m;i++){ if(match[i])match[ match[i] ]=i; } cout<<ans.size()<<endl; for(int i=0;i<ans.size();i++){ printf("%d %d\n",ans[i],match[ ans[i] ]); } // system("pause"); return 0; }
标签:ini its return || hid one mes find font
原文地址:https://www.cnblogs.com/littlerita/p/12764681.html