POJ2446 Bipartite graph maximum point independent set

Find the largest point coverage set in the bipartite graph to see if it can cover all the points in the graph

Not too difficult. . But it's a nightmare for an interstellar player like me. . (I was miserable by the order of x and y, and the capitalization of YES and NO made me WA a whole afternoon QAQ) So it is the correct solution to read the question well. . . .

The time and space complexity constraints of the problem are not stuck, and the water will pass (like my n for loops, there is no pressure to throw them in)

#include<cstdio>
#include<cstring>
const int MAXN=2005;
int G[MAXN][MAXN];
bool b[MAXN];
int link[MAXN];
int m,n,k;
int cnt=0;
bool find(int x)
{
	for(int i=1;i<=cnt;i++)
	{
		if(G[x][i]&&!b[i])
		{
			b[i]=1;
			if(!link[i]||find(link[i]))
			{
				link[i]=x;
				return 1;
			}
		}
	}
	return 0;
}
int ma[MAXN][MAXN];
int num[MAXN][MAXN];
intmain()
{
	while(std::scanf("%d%d%d",&m,&n,&k)!=EOF)
	{
	std::memset(G,0,sizeof(G));
	std::memset(num,0,sizeof(num));
	std::memset(ma,0,sizeof(ma));
	std::memset(link,0,sizeof(link));
	cnt=0;
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)
		{
			ma [i] [j] = 1;
		}
	}
	for(int i=1;i<=k;i++)
	{
		int x,y;
		std::scanf("%d%d",&x,&y);
		ma[y][x]=0;//This is really too much
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(ma[i][j])
			num[i][j]=++cnt;
		}
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(ma[i][j])
			{
			if(i-1>=1&&ma[i-1][j])
			{
				G[num[i][j]][num[i-1][j]]=1;
			}
			if(i+1<=m&&ma[i+1][j])
			{
				G[num[i][j]][num[i+1][j]]=1;
			}
			if(j-1>=1&&ma[i][j-1])
			{
				G[num[i][j]][num[i][j-1]]=1;
			}
			if(j+1<=n&&ma[i][j+1])
			{
				G[num[i][j]][num[i][j+1]]=1;
			}
			}
		}
	}
	int result=0;
	for(int i=1;i<=cnt;i++)
	{
		std::memset(b,0,sizeof(b));
		if(find(i))
		{
			result++;
		}
	}
	if(result==cnt)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}
}
return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324930872&siteId=291194637