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

我的第50道题呀 发个贴纪念一下坑爹的匈牙利算法

Posted by soledada_ at 2012-08-14 09:33:08 on Problem 1325
#include <iostream>
using namespace std;


int d[201];
bool v[201],map[201][201];
int n,m,num;

bool find(int x)
{
	int i,j;
	for(i=n;i<n+m;i++)
		if(map[x][i] && v[i]!=true)
		{
			v[i]=true;
			if(d[i]==-1 || find(d[i]))
			{
				
				d[i]=x;
				return true;
			}
		}
	return false;
}

int process()
{
	int ans=0,i;
	memset( d,-1,sizeof(d) );
	for(i=1;i<n;i++)
	{
		memset(v,false,sizeof(v));
		if(find(i))
			ans++;
	}
	return ans;
}

int main()
{
	int i,j;
	int a,b,c;
	scanf("%d",&n);
while(n!=0)
{
	memset(map,false,sizeof(map));
	scanf("%d %d",&m,&num);

	for(i=0;i<num;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		if(b&&c)
			map[b][c+n]=true;
	}

	printf("%d\n",process());

	scanf("%d",&n);
}//while
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