QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#92676#898. 二分图最大匹配myee#RE 0ms0kbC++112.5kb2023-03-30 20:42:542023-03-30 20:43:03

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-30 20:43:03]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-03-30 20:42:54]
  • 提交

answer

// 那就是希望。
// 即便需要取模,也是光明。

#include <algorithm>
#include <queue>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
    T ans=1%mod;
    while(index)
    {
        if(index&1)ans=ans*base%mod;
        base=base*base%mod,index>>=1;
    }
    return ans;
}
namespace Dinic
{
	uint n;
	uint To[500005],Last[500005],tp;ullt Flow[500005];
	uint End[500005],Cur[500005],Dep[500005];
	voi bzr(uint n){Dinic::n=n,tp=0;for(uint i=0;i<n;i++)End[i]=-1;}
	voi insert(uint u,uint v,ullt f){
		To[tp]=v,Last[tp]=End[u],Flow[tp]=f,End[u]=tp++;
		To[tp]=u,Last[tp]=End[v],Flow[tp]=0,End[v]=tp++;
	}
	bol bfs(uint p,uint t){
		for(uint i=0;i<n;i++)Cur[i]=End[i],Dep[i]=-1;
		std::queue<uint>Q;Q.push(p),Dep[p]=0;
		while(Q.size()){
			p=Q.front(),Q.pop();
			for(uint e=End[p];~e;e=Last[e])
				if(Flow[e]&&_min(Dep[To[e]],Dep[p]+1))Q.push(To[e]);
		}
		return~Dep[t];
	}
	ullt dfs(uint p,uint t,ullt f){
		if(p==t)return f;
		ullt ans=0;
		for(uint&e=Cur[p];~e;e=Last[e])if(Flow[e]&&Dep[To[e]]==Dep[p]+1){
			ullt g=dfs(To[e],t,std::min(f,Flow[e]));
			Flow[e]-=g,f-=g,Flow[e^1]+=g,ans+=g;
			if(!f)return ans;
		}
		return ans;
	}
	ullt run(uint s,uint t){
		ullt ans=0;
		while(bfs(s,t))ans+=dfs(s,t,-1);
		return ans;
	}
}
int main()
{
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
    freopen("QAQ.out","w",stdout);
#endif
	uint l,r,m;scanf("%u%u%u",&l,&r,&m),Dinic::bzr(l+r+2);
	for(uint i=0;i<l;i++)Dinic::insert(l+r,i,1);
	for(uint i=0;i<r;i++)Dinic::insert(l+i,l+r+1,1);
	while(m--){uint u,v;scanf("%u%u",&u,&v),Dinic::insert(u,l+v,1);}
	printf("%llu\n",Dinic::run(l+r,l+r+1));
	for(uint i=0;i<l;i++)if(Dinic::Flow[i<<1|1])
		for(uint e=Dinic::End[i];~e;e=Dinic::Last[e])if(!Dinic::Flow[e])
			printf("%u %u\n",i,Dinic::To[e]-l);
    return 0;
}

// 那就是希望。
// 即便需要取模,也是光明。

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

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: