Lightoj 1201-a Perfect Murder "the largest independent set of two graphs"

Source: Internet
Author: User



Links: http://www.lightoj.com/volume_showproblem.php?problem=1201



Maximum independent set = number of vertices-maximum match



Code:


 
 
#include <iostream>  
#include <algorithm>  
#include <set>  
#include <map>  
#include <string.h>  
#include <queue>  
#include <sstream>  
#include <stdio.h>  
#include <math.h>  
#include <stdlib.h>  

using namespace std;

int n, m;
int p[1010][1010];
int book[1010];
int match[1010];

int dfs(int u)
{
    int i;
    for (i = 1;i <= n;i++)
    {
        if (book[i] == 0 && p[u][i] == 1)
        {
            book[i] = 1;
            if (match[i] == 0 || dfs(match[i]))
            {
                match[i] = u;
                return 1;
            }
        }
    }
    return 0;
}


int main()
{
    int t;
    int cases = 1;
    scanf("%d", &t);
    while (t--)
    {
        int ans = 0;
        memset(match, 0, sizeof(match));
        memset(p, 0, sizeof(p));

        scanf("%d%d", &n, &m);
        int a, b;
        while (m--)
        {
            scanf("%d%d", &a, &b);
            p[a][b] = p[b][a] = 1;

        }

        for (int i = 1;i <= n;i++)
        {
            memset(book, 0, sizeof(book));
            if (dfs(i))
                ans++;
        }
        printf("Case %d: %d\n", cases++,n - ans/2);
    }
    return 0;
}


Copyright NOTICE: Reprint please indicate the source.



Lightoj 1201-a Perfect Murder "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.