HDU 3829 Maximum Independent set

Source: Internet
Author: User

Idea: It is clear that a certain child happy can be done, but at the same time it is possible to let other children unhappy, so each pair of such two children there is a "conflict", if there is "conflict" between the children to build a side, our problem is transformed into a binary map of the largest independent set. Specifically why is a binary chart, Bo Master also did not want to understand ...

1#include <iostream>2#include <cstring>3#include <cstdio>4 using namespacestd;5 6 Const intN =501;7 Const intM = N *N;8 Const intL = One;9 BOOLVisit[n];Ten intHead[n]; One intMark[n]; A intN, M, p, E; -  - structEdge the { -     intV, next; - } Edge[m]; -  + structHobby - { +     CharLike[l], dislike[l]; A } Hobby[n]; at  - voidInit () - { -E =0; -Memset (Head,-1,sizeof(head)); - } in  - voidAddedge (intUintv) to { +EDGE[E].V =v; -Edge[e].next =Head[u]; theHead[u] = e++; * } $ Panax Notoginseng intDfsintu) - { the      for(inti = Head[u]; I! =-1; i =edge[i].next) +     { A         intv =edge[i].v; the         if( !Visit[v]) +         { -VISIT[V] =true; $             if(Mark[v] = =-1||DFS (Mark[v])) $             { -MARK[V] =u; -Mark[u] =v; the                 return 1; -             }Wuyi         } the     } -     return 0; Wu } -  About inthunagry () $ { -memset (Mark,-1,sizeof(Mark)); -     intres =p; -      for(inti =1; I <= p; i++ ) A     { +         if(Mark[i]! =-1)Continue; thememset (Visit,0,sizeof(visit)); -Res-=DFS (i); $     } the     returnRes; the } the  the intMain () - { in      while(SCANF ("%d%d%d", &n, &m, &p)! =EOF) the     { the init (); About          for(inti =1; I <= p; i++ ) the         { thescanf"%s%s", Hobby[i].like, hobby[i].dislike); the              for(intj = i-1; J >0; j-- ) +             { -                 if(strcmp (hobby[i].like, hobby[j].dislike) = =0 the|| strcmp (hobby[j].like, hobby[i].dislike) = =0 )Bayi                 { the Addedge (i, j); the Addedge (J, i); -                 } -             } the         } theprintf"%d\n", Hunagry ()); the     } the     return 0; -}

HDU 3829 Maximum Independent set

Related Article

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.