标签:main nbsp set end test namespace space can ==
1 /* 2 题意:二分图匹配 3 题解: 4 时间:2018.07.18 5 */ 6 7 #include <bits/stdc++.h> 8 using namespace std; 9 10 typedef long long LL; 11 const int MAXN = 100005; 12 const LL MOD7 = 1e9+7; 13 14 struct Edge 15 { 16 int u,v; 17 int next; 18 }edge[2*MAXN]; 19 20 int head[MAXN]; 21 int cnt; 22 23 int mark[MAXN]; 24 int n,m; 25 int vis[MAXN]; 26 27 void init() 28 { 29 cnt=0; 30 memset(head,-1,sizeof(head)); 31 } 32 33 void addEdge(int u,int v) 34 { 35 edge[cnt].u=u;edge[cnt].v=v;edge[cnt].next=head[u];head[u]=cnt++; 36 } 37 38 bool dfs(int u) 39 { 40 for (int i=head[u];i!=-1;i=edge[i].next) 41 { 42 int v=edge[i].v; 43 if (vis[v]) continue; 44 vis[v]=1; 45 if (mark[v]==-1 || dfs(mark[v])) 46 { 47 mark[v]=u; 48 return true; 49 } 50 } 51 return false; 52 } 53 54 void work() 55 { 56 int ans=0; 57 memset(mark,-1,sizeof(mark)); 58 for (int i=1;i<=n;++i) 59 { 60 memset(vis,0,sizeof(vis)); 61 ans+=dfs(i); 62 } 63 printf("%d\n",ans/2); 64 } 65 66 int main() 67 { 68 #ifndef ONLINE_JUDGE 69 freopen("test.txt","r",stdin); 70 #endif // ONLINE_JUDGE 71 scanf("%d%d",&n,&m); 72 int u,v; 73 init(); 74 for (int i=1;i<=m;++i) 75 { 76 scanf("%d%d",&u,&v); 77 addEdge(u,v); 78 addEdge(v,u); 79 } 80 work(); 81 return 0; 82 }
标签:main nbsp set end test namespace space can ==
原文地址:https://www.cnblogs.com/LeeSongt/p/9328263.html