求助,有dalao能看看这是什么写法么?
查看原帖
求助,有dalao能看看这是什么写法么?
120634
2018heyuyang楼主2023/7/27 14:49
#include<cstdio>
#include<cstring>
using namespace std;
const int N=1e6+5;
struct edge
{
	int y,next;
}a[N];int len,last[N];
void ins(int x,int y){a[++len]=(edge){y,last[x]};last[x]=len;}
int match[N];
bool lock[N];
bool find(int x)
{
	for(int k=last[x];k;k=a[k].next)
	{
		int y=a[k].y;
		if(!lock[y])
		{
			lock[y]=1;
			if(match[y]==0||find(match[y]))
			{
				lock[y]=0;match[y]=x;
				return 1;
			}
		}
	}
	return 0;
}
int main()
{
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	int n,m,t;scanf("%d%d%d",&n,&m,&t);
	len=0;memset(last,0,sizeof(last));
	for(int i=1,x,y;i<=t;i++)
	{
		scanf("%d%d",&x,&y);
		ins(x,y);
	}
	int ans=0;memset(match,0,sizeof(match));
	for(int i=1;i<=n;i++)if(find(i))ans++;
	printf("%d\n",ans);
	return 0;
}
2023/7/27 14:49
加载中...