QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#92266#898. 二分图最大匹配youngsystem#TL 0ms0kbC++1.9kb2023-03-30 15:02:272023-03-31 10:28:00

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-31 10:28:00]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-03-30 15:02:27]
  • 提交

answer

#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read()
{
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}
int n,m,s,t;
struct bbian
{
	int u,v,w,nex;
}a[1600004];
int head[400005],tmp=1;
void addb(int x,int y,int z)
{
	a[++tmp].u=x;
	a[tmp].v=y;
	a[tmp].w=z;
	a[tmp].nex=head[x];
	head[x]=tmp;
}
int dis[400005];
queue<int>que;
bool bfs()
{
	for(int i=1;i<=t;i++)dis[i]=1000000000;
	dis[s]=0;
	que.push(s);
	while(!que.empty())
	{
		int x=que.front();
		que.pop();
		for(int i=head[x];i;i=a[i].nex)
		{
			if(a[i].w==0)continue;
			if(dis[a[i].v]>dis[x]+1)
			{
				dis[a[i].v]=dis[x]+1;
				que.push(a[i].v);
			}
		}
	}
	if(dis[t]==1000000000)return false;
	return true;
}
int cur[400005];
int dfs(int x,int rf)
{
	if(rf==0)return 0;
	if(x==t)return rf;
	int ans=0;
	for(int i=head[x];i;i=a[i].nex)
	{
		if(dis[a[i].v]!=dis[x]+1||a[i].w==0)continue;
		int sth=dfs(a[i].v,min(rf,a[i].w));
		if(sth==0)
		{
			dis[a[i].v]=1000000000;
			continue;
		}
		a[i].w-=sth;
		a[i^1].w+=sth;
		ans+=sth;
		rf-=sth; 
		if(!rf)break;
	}
	return ans;
}
int bu[500005],bv[500005],p[500005];
mt19937 ran(121296);
signed main()
{
	int l,r,m;
	l=read();
	r=read();
	m=read();
	s=l+r+1;
	t=l+r+2; 
	int x,y,z;
	for(int i=1;i<=m;i++)
	{
		bu[i]=read();
		bv[i]=read();
		p[i]=i;
	}
	shuffle(p+1,p+n+1,ran);
	for(int i=1;i<=m;i++)
	{
		x=bu[p[i]]+1;
		y=bv[p[i]]+l+1;
		addb(x,y,1);
		addb(y,x,0);
	}
	for(int i=1;i<=l;i++)addb(s,i,1),addb(i,s,0);
	for(int i=l+1;i<=l+r;i++)addb(i,t,1),addb(t,i,0);
	int ans=0;
	while(bfs())
	{
		ans+=dfs(s,1000000000);
	}
	printf("%d\n",ans);
	for(int i=1;i<=m;i++)
	{
		//printf("%lld %lld\n",a[2*i].u,a[2*i].v);
		if(a[2*i].w==0)printf("%d %d\n",a[2*i].u-1,a[2*i].v-l-1);
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

100000 100000 200000
78474 45795
32144 46392
92549 13903
73460 34144
96460 92850
56318 77066
77529 84436
76342 51542
77506 99268
76410 89381
1778 61392
43607 96135
84268 74827
14857 35966
32084 94908
19876 174
1481 94390
12423 55019
64368 92587
81295 7902
25432 46032
36293 61128
73555 84836
8418 102...

output:


result: