Determination of complete hdu1083 matching

Source: Internet
Author: User

Go directlyCode.

 /*  * Hdu1083/win. cpp * created on: 2012-8-16 * Author: Ben  */  # Include <Cstdio> # Include <Cstdlib> # Include <Cstring> # Include <Cmath> # Include <Ctime> # Include <Iostream> # Include <Algorithm> # Include <Queue># Include < Set > # Include <Map> # Include <Stack> # Include < String > # Include <Vector> # Include <Deque> # Include <List> # Include <Functional> # Include <Numeric> # Include <Cctype> Using   Namespace  STD;  Const   Int Maxn = 305  ; Vector < Int > Mymap [maxn];  Int  N, m, mymatch [maxn];  Bool  Visited [maxn];  Void  Init (){ For ( Int I = 0 ; I <n; I ++ ) {Mymap [I]. Clear ();}}  Bool DFS ( Int  K ){  Int  T, I;  For ( Int I = 0 ; I <( Int ) Mymap [K]. Size (); I ++ ) {I = Mymap [k] [I];  If (! Visited [I]) {visited [I] = True  ; T = Mymatch [I]; mymatch [I] = K;  If (T =- 1 | DFS (t )){  Return   True  ;} Mymatch [I] = T ;}}  Return   False  ;}  Int  Hungary () {memset (mymatch, - 1 , Sizeof  (Mymatch ));  Int Ans = 0  ;  For ( Int I = 0 ; I <n; I ++ ) {Memset (visited,  False , Sizeof  (Visited ));  If  (DFS (I) {ans ++ ;}}  Return  Ans ;}  Bool  Buildgraph (){  Int  T, K; Init ();  For (Int I = 0 ; I <n; I ++ ) {Scanf (  "  % D  " ,& K );  For ( Int K = 0 ; K <K; k ++ ) {Scanf (  "  % D  " ,&T); mymap [I]. push_back (T - 1  );}}  Return   True  ;}  Int  Main () {# ifndef online_judge freopen (  "  Data. In  " , "  R  "  , Stdin );  # Endif     Int  T, P; scanf (  "  % D  " ,& T );  While (T -- ) {Scanf (  "  % D  " , & N ,& P); buildgraph (); puts (Hungary () = N? "  Yes  " :"  No  "  );}  Return   0  ;} 

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.