HDU 1068 Girls and Boys (the largest independent set of two graphs)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1068

There are n classmates, the format ni: (m) N1 n2 N3 said classmate Ni destined and n1,n2,n3 become a couple, ask the collection does not exist in the first couple of classmates the biggest classmate number.

Independent set (a subset of the vertex sets of the graph, where any two points are not adjacent)

Maximum independent set = vertex number-Maximum match number in a binary graph

Because men and women do not know, to split a person into two gender, the maximum match, divided by 2 on the line.

This approach is more difficult to understand.

1#include <iostream>2#include <cstdio>3#include <cstring>4 using namespacestd;5 Const intN = 1e3 +5;6 structEdge {7     intnext, to;8}edge[n *N];9 intHead[n], CNT;Ten intMatch[n]; One BOOLVis[n]; A  - voidinit () { -Memset (Head,-1,sizeof(head)); thememset (Match,-1,sizeof(Match)); -memset (Vis,false,sizeof(Vis)); -CNT =0; - } +  -InlinevoidAddintU,intv) { +Edge[cnt].next =Head[u]; AEdge[cnt].to =v; atHead[u] = cnt++; - } -  - BOOLDfsintu) { -      for(inti = Head[u]; ~i; i =Edge[i].next) { -         intv =edge[i].to; in         if(!Vis[v]) { -VIS[V] =true; to             if(Match[v] = =-1||DFS (Match[v])) { +MATCH[V] =u; -                 return true; the             } *         } $     }Panax Notoginseng     return false; - } the  + intHungry (intN) { A     intres =0; the      for(inti =0; I < n; ++i) { +memset (Vis,false,sizeof(Vis)); -         if(Dfs (i)) $res++; $     } -     returnRes; - } the  - intMain ()Wuyi { the     intN; -      while(~SCANF ("%d", &N)) { Wu init (); -         intv; About          for(inti =0; I < n; ++i) { $             intnum1, num; -scanf"%d: (%d)", &AMP;NUM1, &num); -              while(num--) { -scanf"%d", &v); A Add (i, v); +             } the         } -printf"%d\n", N-hungry (n)/2); $     } the     return 0; the}

HDU 1068 Girls and Boys (the largest independent set of two graphs)

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.