QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#340869#898. 二分图最大匹配ffffyc#TL 0ms0kbC++142.3kb2024-02-29 13:40:162024-02-29 13:40:18

Judging History

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

  • [2024-02-29 13:40:18]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-02-29 13:40:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace IO{//by cyffff
	int len=0;
	char ibuf[(1<<21)+1],*iS,*iT,out[(1<<25)+1];
	#if ONLINE_JUDGE
	#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
 	#else
	#define gh() getchar()
	#endif
	#define reg register
	inline int read(){
		reg char ch=gh();
		reg int x=0;
		reg char t=0;
		while(ch<'0'||ch>'9')   t|=ch=='-',ch=gh();
		while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
		return t?-x:x;
	}
	inline void putc(char ch){
		out[len++]=ch;
	}
	template<class T>
	inline void write(T x){
		if(x<0)putc('-'),x=-x;
		if(x>9)write(x/10);
		out[len++]=x%10+48;
	}
	inline void flush(){
		fwrite(out,1,len,stdout);
		len=0;
	}
	inline char getc(){
		char ch=gh();
		while(ch<'A'||ch>'Z') ch=gh();
		return ch;
	}
}
using IO::read;
using IO::write;
using IO::flush;
using IO::getc;
using IO::putc;
const int N=100+10,M=1e4+10;
const ll INF=1e10;
int n1,n2,m,head[N],cnt=1;
struct Edge{
	int to,nxt,fl;
}a[M];
inline void Add(int u,int v,int w){
	a[++cnt]={v,head[u],w},head[u]=cnt;
}
inline void add(int u,int v,int w){
	Add(u,v,w),Add(v,u,0);
}
int thd[N],dep[N],s,t;
inline bool bfs(){
	for(int i=1;i<=t;i++)
		thd[i]=head[i],dep[i]=t+1;
	queue<int>q;
	q.push(s),dep[s]=0;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=head[x];i;i=a[i].nxt){
			int t=a[i].to;
			if(a[i].fl&&dep[t]>dep[x]+1)
				dep[t]=dep[x]+1,q.push(t);
		}
	}
	return dep[t]<=t;
}
inline ll dfs(int x,ll fl){
	if(x==t) return fl;
	ll s=0;
	for(int i=thd[x];i&&fl;i=a[i].nxt){
		thd[x]=i;
		int t=a[i].to;
		if(dep[t]==dep[x]+1&&a[i].fl){
			ll res=dfs(t,min(fl,a[i].fl+0ll));
			a[i].fl-=res,a[i^1].fl+=res,fl-=res,s+=res;
		}
	}
	return s;
}
inline ll dinic(){
	ll sum=0;
	while(bfs())
		sum+=dfs(s,INF);
	return sum;
}
int main(){
	n1=read(),n2=read(),m=read(),s=n1+n2+1,t=s+1;
	for(int i=1;i<=n1;i++)
		add(s,i,1);
	for(int i=n1+1;i<=n1+n2;i++)
		add(i,t,1);
	for(int i=1;i<=m;i++){
		int u=read()+1,v=read()+1+n1;
		add(u,v,1);
	}
	write(dinic()),putc('\n');
	for(int i=1;i<=n1;i++){
		for(int j=head[i];j;j=a[j].nxt){
			int t=a[j].to;
			if(t<=n1+n2&&!a[j].fl) write(i-1),putc(' '),write(t-n1-1),putc('\n');
		}
	}
	flush();
}

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: