Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

16MS代码,最小覆盖=定点数-最大匹配

Posted by speedcell4 at 2011-08-17 15:19:43 on Problem 1422 and last updated at 2011-08-17 15:19:53
#include<iostream>
#define SIZE 120
using namespace std;
int tcase,n,m,x,y;
int t[SIZE];
bool v[SIZE],a[SIZE][SIZE];
bool find(int x)
{
    for(int i=0;n-i>0;i++)
    {
        if(v[i]==false&&a[x][i]==true)
        {
            v[i]=true;
            if(t[i]==-1||find(t[i]))
            {
                t[i]=x;
                return true;
            }
        }
    }
    return false;
}
int findMatch(void)
{
    int count=0;
    for(int i=0;n-i>0;i++)
    {
        memset(v,false,sizeof(v));
        if(find(i)) count++;
    }
    return count;
}
int main()
{
    scanf("%d",&tcase);while(tcase--)
    {
        memset(t,-1,sizeof(t));
        memset(a,false,sizeof(a));
        scanf("%d %d",&n,&m);
        for(int i=0;m-i>0;i++)
        {
            scanf("%d %d",&x,&y);
            a[x-1][y-1]=true;
        }
        printf("%d\n",n-findMatch());
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator