Bzoj 1854 [Scoi2010] game binary graph Max match

Source: Internet
Author: User

Test Instructions:
n equipment, two attributes, the value of the property in the range of 1~10000, encountered a boss, need to use a continuous increment of the value of the property from 1 to attack, and one device can only be used once, ask the maximum number of hits.
parsing:
The best match for a classic binary chart?
The property value matches the first few.
So the direct map to run the maximum match can be.
But this one, every time we clear the array, it doesn't work--
is also the card I quite long time, also thought the binary chart biggest match too, later read the topic explanation with the time stamp, too God too God also has such fun thing--how I did not know.
Code:

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 1000100using namespace STD;intv[n<<1];intmatch[n<<1];inthead[n<<1];intCntintNintNowtime;structnode{intFrom,to,next;} edge[n<<1];voidInit () {memset(head,-1,sizeof(head)); Cnt=1;}voidEdgeadd (intFromintTo) {Edge[cnt].from=from,edge[cnt].to=to,edge[cnt].next=head[from]; head[from]=cnt++;}BOOLFindintx) { for(inti=head[x];i!=-1; i=edge[i].next) {intto=edge[i].to;if(V[to]!=nowtime) {v[to]=nowtime;if(!match[to]| | Find (Match[to])) {match[to]=x;return 1; }        }    }return 0;}intMain () {init ();scanf("%d", &n); for(intI=1; i<=n;i++) {intx, y;scanf("%d%d", &x,&y);    Edgeadd (X,i), Edgeadd (y,i); } for(intI=1; i<=n;i++) {nowtime++;if(!find (i)) {printf("%d\n", I-1);return 0; }    }printf("%d\n", n);}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Bzoj 1854 [Scoi2010] game binary graph Max match

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.