uva12083 binary graph for maximum independent set conversion to find maximum match by test instructions two-point chart

Source: Internet
Author: User
Tags strcmp

Examples of this great White Book:

Frank was a conservative high school teacher who once had to take some students out on a trip, but was afraid that some of them would love to be on the road. In order to reduce the probability of this happening, he decided to make sure that any two students brought out at least meet one of the following 4 articles

1 height difference is greater than 40

2 Sex Same

3 favorite music belongs to different types

4 Favorite sports games of the same

The task group Frank picked as many students as possible, so that any two students meet at least one of the above conditions.

The solution will not be able to go at the same time the person can become the maximum independent set, that is, select as many nodes as possible, so that any two nodes are not adjacent. | maximum independent set |+| minimum vertex cover | =| X 2 Maximum match for minimum vertex overlay in a binary graph

Because of the presence of male and female travel at this time can be guaranteed to be a two-part map

1#include <iostream>2#include <algorithm>3#include <string.h>4#include <cstdio>5#include <vector>6 using namespacestd;7 Const intMAXN =505;8 structperson{9    intnum;Ten    intHigh ; One    Charmale[2]; A    Charlove_muc[ Max]; -    Charlove_ty[ Max]; - }P[MAXN]; the  - structBPM { -    intN, M;//number of left and right vertices -vector<int> G[MAXN];//adjacency Table +    intLEFT[MAXN];//Left[i] is the number of the match point on the right point I, 1 indicates that there is no -    BOOLT[MAXN];//T[i] to the right of the first I point is marked +    intRIGHT[MAXN];//for minimum coverage A    BOOLS[MAXN];//for minimum coverage at    voidIntiintNintm) { -          This->n =n; This->m=m; -          for(intI=0; i<n; i++) g[i].clear (); -    } -     voidADD_EDG (intUintv) { - G[u].push_back (v); in     } -     BOOLMatchintu) { tos[u]=true; +         for(intI=0; I<g[u].size (); i++){ -             intto =G[u][i]; the             if(!T[to]) { *t[to]=true; $                  if(left[to]==-1||match (Left[to])) {Panax NotoginsengLeft[to]=u; right[u]=to ; -                        return true; the                  } +             } A        } the        return false; +     } -     intsolve () { $memset (left,-1,sizeof(left)); $memset (right,-1,sizeof(right)); -         intans=0; -          for(intI=0; i<n; i++){ thememset (S),false,sizeof(S)); -memset (T,false,sizeof(T));Wuyi               if(Match (i)) ans++; the         } -         returnans; Wu     } - }solver; About  $ intMain () - { -     intCAs; -scanf"%d",&CAs); A      for(intCC =1; cc<=cas; ++cc) { +         intN; thescanf"%d",&n); -         intmnum=0, fnum=0; $           for(intI=0; i<n; i++){ thescanf"%d%s%s%s",&p[i].high,p[i].male,p[i].love_muc,p[i].love_ty); the             if(p[i].male[0]=='M') p[i].num=mnum++; the             Elsep[i].num=fnum++; the          } - Solver.inti (mnum,fnum); in          for(inti =0; i<n; i++)if(p[i].male[0]=='M'){ the  the               for(intj=0; j<n; J + +) About                 if( thep[j].male[0]=='F'&&abs (P[i].high-p[j].high) <= + the&AMP;&AMP;STRCMP (P[I].LOVE_MUC,P[J].LOVE_MUC) = =0&& thestrcmp (p[i].love_ty,p[j].love_ty)! =0 + ) SOLVER.ADD_EDG (p[i].num,p[j].num); -  the         }Bayi          intAns =solver.solve (); theprintf"%d\n", N-ans); the     } -     return 0; -}

uva12083 binary graph for maximum independent set conversion to find maximum match by test instructions two-point chart

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.