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 chenxuan123456789 at 2012-09-11 16:02:56 on Problem 3041
#include <stdio.h>
#include <string.h>
#define len 510
int map[len][len];
int used[len];
int link[len];
int n;
int dfs(int a)
{
	int i;
	for(i=1;i<=n;i++)
	{
		if(!used[i]&&map[a][i])
		{
			used[i]=1;
			if(link[i]==-1||dfs(link[i]))
			{
				link[i]=a;
				return 1;
			}
		}
	}
	return 0;
}
int main()
{
	int a,b,m,sum,i;
	while(scanf("%d %d",&n,&m)!=EOF)
	{
		memset(map,0,sizeof(map));
		memset(link,-1,sizeof(link));
		while(m--)
		{
			scanf("%d %d",&a,&b);
			map[a][b]=1;
		}
		sum=0;
		for(i=1;i<=n;i++)
		{
			memset(used,0,sizeof(used));
			if(dfs(i))
				sum++;
		}
		printf("%d\n",sum);
	}
	return 1;
}

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