Title: https://www.lydsy.com/JudgeOnline/problem.php?id=1854
This question ... It is said that you can use and check the collection to do, but not to see ...
With the binary graph matching, the equipment and its two properties of the edge, and then from the beginning of the property from small to large Hungarian algorithm;
This ensures that the previous match is successful when matching this property;
So when we meet the situation can not match the end, the output can be;
Be careful with tle, so avoid memset.
The code is as follows:
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;int Constmaxn=1000005, maxm=10005;intN,head[maxm],ct,pre[maxn],mx,ans;intVIS[MAXN];structn{intTo,next; N (intt=0,intn=0): to (T), next (n) {}}EDGE[MAXN<<1];voidAddintXintY) {edge[++ct]=n (y,head[x]); head[x]=CT;}BOOLDfsintx) { for(intI=head[x],u;i;i=Edge[i].next) { if(vis[u=edge[i].to]!=ans)//if (!vis[u=edge[i].to])//tle!{Vis[u]=ans; if(!pre[u]| |DFS (Pre[u])) {Pre[u]=x;return 1; } } } return 0;}intMain () {scanf ("%d",&N); for(intI=1, x,y;i<=n;i++) {scanf ("%d%d",&x,&y); Add (x,i); Add (y,i); MX=Max (Mx,max (x, y)); } for(intI=1; i<=mx;i++) {//memset (vis,0,sizeof vis);//tle!ans++; if(!DFS (i)) {printf ("%d\n", ans-1);return 0; }} printf ("%d", ans); return 0;}
bzoj1854 [Scoi2010] Game--Hungarian algorithm