bzoj1854: [Scoi2010] Games

Source: Internet
Author: User

The maximum match of the binary graph. Connect the two attributes of each weapon with this weapon. Enumeration property, which cannot be matched on the output.

Basic concepts: (oral unofficial)

Two-part diagram: The vertices of a graph are divided into two parts, each of which has no edges attached to each point.

Match: In the binary graph, find some edges, each side has no common point.

Maximum match: the maximum match.

Perfect match: Each point is used on the match, the number of hops = points.

In fact, the maximum matching of the binary graph can be explained by the maximum flow algorithm. Each edge has a capacity of 1. But the efficiency is not high.

Hungarian algorithm.

#include <cstdio>#include<algorithm>#include<cstring>using namespacestd;Const intMAXN =1000000+Ten;Const intMAXM =4000000+Ten;Const intMAXV =10000+Ten;intN,eid;intH[MAXV],TO[MAXM],NEXT[MAXM],V[MAXM];intP[MAXN];BOOLVIS[MAXV];voidAddintAintb) {V[eid]= b; Next[eid] = H[a]; H[a] = eid++;}BOOLFindintu) {if(Vis[u])return false; Vis[u]=true;  for(inti = h[u];~i; i =Next[i]) {        if(!p[v[i] | |find (P[v[i])) {P[v[i]]=u; return true; }    }        return false;}intMain () {scanf ("%d",&N); memset (H,-1,sizeof(h));  for(inti =1, A, B; I <= N; i++) {scanf ("%d%d",&a,&b);        Add (a,i);    Add (b,i); }    intRes;  for(res =1; Res <=10000; res++) {memset (Vis,0,sizeof(VIS)); if(!find (RES)) Break; } printf ("%d\n", res-1); return 0;}

bzoj1854: [Scoi2010] Games

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: 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.