QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#64698#898. 二分图最大匹配LinkZelda#TL 0ms0kbC++141.7kb2022-11-25 12:09:322022-11-25 12:09:34

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-25 12:09:34]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2022-11-25 12:09:32]
  • 提交

answer

#include<bits/stdc++.h> 
#define pr pair<int,int>
#define eps 1e-7
#define int long long

using namespace std;

inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int N=500005,M=1000005,INF=0x7f7f7f7f;
int head[N],to[M],nxt[M],w[M],cnt=1,s,t;
void add(int u,int v,int wi)
{
	to[++cnt]=v;
	nxt[cnt]=head[u];
	head[u]=cnt;
	w[cnt]=wi;
}

int dis[N],n,m,now[N];

bool bfs()
{
	fill(dis,dis+n+1,INF);queue<int>Q;
	Q.push(s);dis[s]=0;now[s]=head[s];
	while(!Q.empty())
	{
		int u=Q.front();Q.pop();
		for(int i=head[u];i;i=nxt[i])
		{
			int v=to[i];
			if(w[i]>0&&dis[v]==INF)
			{
				dis[v]=dis[u]+1;
				Q.push(v);
				now[v]=head[v];
				if(v==t)
					return true;
			}
		}
	}
	return false;
}

int work(int u,int f)
{
	if(u==t)
		return f;
	int ret=0;
	for(int i=now[u];i;i=nxt[i])
	{
		now[u]=nxt[i];int v=to[i];
		if(w[i]>0&&dis[v]==dis[u]+1)
		{
			int qwq=work(v,min(f,w[i]));
			w[i]-=qwq;w[i^1]+=qwq;
			ret+=qwq;f-=qwq;
			if(!qwq)
				dis[v]=INF;
		}
	}
	return ret;
}

int ans,l,r;

signed main()
{
	l=read(),r=read(),m=read();n=l+r;
	s=++n,t=++n;
	for(int x,y,i=1;i<=m;i++)
		x=read()+1,y=read()+1,add(x,y+l,INF),add(y+l,x,0);
	for(int i=1;i<=l;i++)
		add(s,i,1),add(i,s,0);
	for(int i=1;i<=r;i++)
		add(i+l,t,1),add(t,i+l,0);
	while(bfs())
		ans+=work(s,INF);
	printf("%lld\n",ans);
	for(int j=1;j<=l;j++)
	{
		for(int i=head[j];i;i=nxt[i])
		{
			int v=to[i];
			if(v==s)
				continue;
			if(w[i^1]&&w[i]&&w[i^1]+w[i]==INF)
				printf("%lld %lld\n",j-1,v-l-1);
		}
	}
	return 0;
}

详细

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: