hdu2063 roller coaster (maximum two-point match)

Source: Internet
Author: User

Highly recommended Hungarian algorithm introduction: http://www.renfei.org/blog/bipartite-matching.html

1#include"iostream"2#include"Vector"3#include"Memory.h"4 using namespacestd;5 #defineSwap (A,b,t) ((t) = (x), (x) = (y), (y) = (t))6 #defineMAXN 10107 intL[MAXN][MAXN];8 BOOLFLAG[MAXN];9 intRE[MAXN];Ten intK,m,n; One intans; A  - intFindinta) - { the      for(inti =0; I <= N; ++i) { -         if(L[a][i] = =1&& Flag[i] = =0) { -Flag[i] =1; -             if(Re[i] = =0||find (Re[i])) { +Re[i] =A; -                 return 1; +             } A         } at     } -     return 0; - } -  - voidInit () - { inAns =0; -      for(inti =0; I <= m; ++i) to          for(intj =0; J <= N; ++j) +L[I][J] =0; -memset (Re,0,sizeof(re)); the } *  $ intMain ()Panax Notoginseng { -  the      while(Cin >>k,k) { + init (); AAns =0; theCIN >> M >>N; +          for(inti =0; I < K; ++i) { -             intb; $Cin >> a >>b; $L[A][B] =1; -         } -          for(inti =1; I <= m; ++i) { thememset (Flag,0,sizeof(flag)); -             if(Find (i)) ans + +;Wuyi         } thecout << ans <<Endl; -     } Wu     return 0; -}
DFS

Owed a BFS

hdu2063 roller coaster (maximum two-point 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.