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

为什么会WA呢 那位大牛帮忙看看!!

Posted by 20082741 at 2010-03-07 11:27:55 on Problem 1469
#include<iostream>
#include<cstring>

using namespace std;

int m, P, N, count, stu, ans = 0;
int result[101];
int used[101];
int data[301][101];

bool find( int v )
{
	for( int j = 1; j <= P; ++j )
	{
		if( data[v][j] && !used[j] )
		{
			used[j] = 1;
			if( result[j] == 0 || find(result[j]) )
			{
				result[j] = v;
				return true;
			}
		}
	}
	return false;
}

void init()
{
	memset(data,0,sizeof(data));
	memset(result,0,sizeof(result));
	scanf("%d %d",&P,&N);
	if( P > N ) 
	{
		printf("NO\n");
		return;
	}
	for( int i = 1; i <= P; i++ )
	{
		scanf("%d",&count);
		for( int j = 1; j <= count; ++j )
		{
			scanf("%d",&stu);
			data[i][stu] = 1;
		}
	}
	
    ans = 0;
	for( int j = 1; j <= N; ++j )
	{
		memset(used,0,sizeof(used));
		if( find(j) ) ans++;
	}
	if( ans == P )
		printf("YES\n");
	else
		printf("NO\n");
	return ;
}

int main()
{
	scanf("%d",&m);
	while( m-- )
	    init();
	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