"Hdoj 1068" Girls and Boys

Source: Internet
Author: User

"Hdoj 1068" Girls and Boys

The maximum independent set problem of binary graphs
Originally wanted to use the largest independent set = complement map of the largest group to do. Result timed out
Then we use the maximum independent set of the binary graph = vertex number-Two graph maximum match to do,. The VIS array is not good and super finally changed to change the right ...

Since the input map is bidirectional, the maximum match is reduced by twice times

The code is as follows:

#include <cstdlib> #include <cstdio> #include <cstring> #include <iostream> #include <vector

> Using namespace std;
Vector <int> head[555];
BOOL vis[555];

int link[555],n;
    BOOL can (int p) {int i,v;
        for (i = 0; i < head[p].size (); ++i) {v = head[p][i]; if (!vis[v]) {Vis[v] = true;//.
                Do not change back to false after recursion otherwise it will be traversed many times as useless operation if (link[v] = = 1 | | can (LINK[V])) {link[v] = p;
            return 1;
}}} return 0;
    } int main () {int m,i,j,u,v,cnt;
        while (~SCANF ("%d", &n)) {for (i = 0; i < n; ++i) head[i].clear ();

        CNT = 0;
            for (i = 0; i < n; ++i) {scanf ("%d: (%d)", &u,&m);
                while (m--) {scanf ("%d", &v);
            Head[u].push_back (v);
        }} memset (Link,-1,sizeof (link)); for (i = 0; i < n;++i) {memset (vis,0,sizeof (VIS));
        if (Can (i)) cnt++;
    } printf ("%d\n", N-CNT/2);
} 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.