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

哪位高手帮忙看一下,为什么总是WR,查不出错了

Posted by gui at 2005-09-23 18:03:25 on Problem 2594
//WR
#include<iostream.h>
#include<string.h>

int con[500][500];
int last[500];
int match[500];
int n,m;

int Dfs(int);

int main()
{
	int i,ans,x,y;
	cin >> n >> m;
	while (n+m)
	{
		memset(con,0,sizeof(con));
		memset(match,-1,sizeof(match));
		for(i=0;i<m;i++)
		{
			cin >> x >> y;
			con[x-1][y-1]=1;
		}
		ans=0;
		for(i=0;i<n;i++)
		{
			memset(last,0,sizeof(last));
			if (Dfs(i))
				ans++;
		}
		cout << n-ans << endl;
		cin >> n >> m;
	}
	return 0;
}

int Dfs(int p)
{
  int i,t;
  for(i=0;i<n;i++)
    if(con[p][i] && !last[i])
    {
      last[i]=1;
      t=match[i];
      match[i]=p;
      if(t==-1 || Dfs(t))
          return 1;
      match[i]=t;
    }
  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