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

纪念1A,贴个代码

Posted by louchiheng at 2016-03-27 10:40:30 on Problem 3041
#include<cstdio>
#include<string.h>
using namespace std;
bool map[501][501],b[501],g[501];
int i,n,m,k,ans=0,x,y,r[501];
bool dfs(int k)
{
	g[k]=1;
	for(int j=1;j<=n;++j)
	if(map[k][j])
	{
		if(b[j]==0)
		{
    		b[j]=1;
    		r[j]=k;
    		return 1;
    	}
    	if(!g[r[j]]&&dfs(r[j]))
    	{
    		b[j]=1;
    		r[j]=k;
    		return 1;
		}
	}
	return 0;
}
int main()
{
	scanf("%d%d",&n,&m);
	memset(map,0,sizeof(map));
	memset(b,0,sizeof(b));
	for(i=1;i<=m;++i)
	{
		scanf("%d%d",&x,&y);
		map[x][y]=1;
	}
	for(i=1;i<=n;++i)
	{
		memset(g,0,sizeof(g));
	    if(dfs(i))ans++;
    }
	printf("%d\n",ans);
}

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