HDU-3829 Cat VS Dog

Source: Internet
Author: User

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

#include <iostream> #include <cstdio> #include <string> #include <cstring> #include < algorithm>using namespace std; #define M 510#define N 250010int head[m], next[n], Key[n];int match[m];string like[m], di SLIKE[M];    Like, don't like bool Use[m];int num;int child;void Add (int u, int v)//adjacency table save diagram {Key[num] = V;    Next[num] = Head[u]; Head[u] = num++;}    BOOL Find (int u)//Match {int temp;        for (int i = head[u]; i =-1; i = Next[i]) {temp = Key[i];            if (!use[temp]) {use[temp] = true;                if (match[temp] = = 1 | | find (MATCH[TEMP])) {match[temp] = u;            return true; }}} return false;}    int Hungary ()//Hungarian algorithm, split match {int sum = 0;        for (int i = 0; i < child; ++i) {memset (use, False, sizeof (use));    if (find (i)) sum++; } return sum;}    int main () {int cat, dog;    String Likeit, Dislikeit; while (scanf ("%d%d%d", &cat, &dog, &chiLD)! = EOF) {num = 0;        Memset (Head,-1, sizeof (head));        memset (Match,-1, sizeof (match)); for (int i = 0; i < child; ++i) {cin>>likeit>>dislikeit;//like animals, not animals like[i] = Likeit;        Record Dislike[i] = Dislikeit; } for (int i = 0; i < child; ++i)//must establish bidirectional edge for (int j = 0; j < child; ++j) if (like[i ].compare (dislike[j]) = = 0 | |        Dislike[i].compare (like[j]) = = 0)//Add contradiction side Add (i, j); printf ("%d\n", Child-hungary ()/2); Maximum independent set (2 matches, except 2)} return 0;


HDU-3829 Cat VS Dog

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.