WA on # 5求调
查看原帖
WA on # 5求调
1043658
Purple_meteor楼主2024/11/19 15:34

代码:

#include<bits/stdc++.h>
using namespace std;
bool f[501][501];
int n,m,e;
int ans;
struct point
{
	int head,l;
	bool vis;
}p[2][501];
struct line
{
	int next,to;
}l[100000];
int cnt=2;
void mkline(int ll,int rr)
{
	f[ll][rr]=1;
	l[cnt].to=rr;
	l[cnt].next=p[0][ll].head;
	p[0][ll].head=cnt;
	cnt++;
	l[cnt].to=ll;
	l[cnt].next=p[1][rr].head;
	p[1][rr].head=cnt;
	cnt++;
}
bool match(int x,int num)
{
	bool f=0;
	if(!num) return 0;
	if(!p[1][l[num].to].vis)
	{
		int ll=x,rr=l[num].to;
		p[0][ll].l=num;
		p[1][rr].l=num^1;
		p[1][rr].vis=1;
		return 1;
	}
	int py=l[p[1][l[num].to].l].to;
	for(int i=p[0][py].l;i;i=l[i].next)
	if(!p[1][l[i].to].vis)
	{
		f=match(py,i);
		break;
	}
	if(f)
	{
		int ll=x,rr=l[num].to;
		p[0][ll].l=num;
		p[1][rr].l=num^1;
		p[1][rr].vis=1;
	}
	
	return f;
}
int main()
{
	cin>>n>>m>>e;
	while(e--)
	{
		int l,r;
		cin>>l>>r;
		if(f[l][r]) continue;
		mkline(l,r);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=p[0][i].head;j;j=l[j].next)
		{
			if(match(i,j))
			{
				ans++;
				break;
			}
		}
	}
	cout<<ans;
	return 0;
}

另加一组能把这份代码hack的数据:

Input

3 3 5
1 2
1 3
2 1
2 3
3 2

Output

2

ans

3
2024/11/19 15:34
加载中...