bzoj1854 [Scoi2010] Game--Hungarian algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.