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

我不知道哪里错了

Posted by 2009550934 at 2011-08-08 14:39:37 on Problem 1469
#include<iostream>
#include<cstring>
#include<cstdio>
#define init(x) memset(x,0,sizeof(x))
#define init0xff(x) memset(x,0xff,sizeof(x))
using namespace std;

int c1[301],c2[301];
int g[301][301];
int mk[301];
int n,m;

int path(int u)
{
    int v;
    for(v = 1; v<= n;v ++)
    {
        if(g[u][v] == 1 && !mk[v])
        {
            mk[v] = 1;
            if(c2[v] == -1 || path(c2[v]))
            {
                c1[u] = v;
                c2[v] = u;
                return 1;
            }
        }
    }
    return 0;
}

int MaxMatch()
{
    int ret = 0 ,i;
    init0xff(c1);
    init0xff(c2);
    for(i = 1;i <= n;i++)
    {
        if(c1[i]== -1)
        {
            //cout <<1 << endl;
            init(mk);
            if(path(i))
            ret ++;
        }
    }
    return ret;
}

int main()
{
    int i,x,y,j;
    int t,s,num;
    scanf("%d",&t);
    while(t--)
    {
        init(g);
        scanf("%d%d",&n,&m);
        for(i = 1 ;i <= n;i++)
        {
            scanf("%d",&s);
            for(j =1 ;j <= s;j++)
            {
                scanf("%d",&num);
                g[i][num] = 1;
            }
        }
        if(MaxMatch() == n)
        {
            printf("YES\n");
        }
        else
        printf("NO\n");
    }
    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