QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#127264 | #898. 二分图最大匹配 | myee# | RE | 0ms | 0kb | C++11 | 2.8kb | 2023-07-19 14:56:20 | 2023-07-19 14:56:23 |
Judging History
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;
}
// Heaven and Earth... My guiding star...
// Akira Complex R.I.P.
namespace Dinic
{
uint To[400005],Last[400005],End[100005],Dist[100005],Cur[100005],n,tp;bol Flow[400005];
voi build(uint n){Dinic::n=n,tp=0;for(uint i=0;i<n;i++)End[i]=-1;}
voi insert(uint u,uint v)
{
To[tp]=v,Last[tp]=End[u],Flow[tp]=true,End[u]=tp++;
To[tp]=u,Last[tp]=End[v],Flow[tp]=false,End[v]=tp++;
}
bol bfs(uint p,uint t)
{
for(uint i=0;i<n;i++)Dist[i]=-1,Cur[i]=End[i];
Dist[p]=0;std::queue<uint>Q;Q.push(p);
while(Q.size())
{
p=Q.front(),Q.pop();if(p==t)return true;
for(uint e=End[p];~e;e=Last[e])
if(Flow[e]&&_min(Dist[To[e]],Dist[p]+1))Q.push(To[e]);
}
return false;
}
bol dfs(uint p,uint t)
{
if(p==t)return true;
for(uint&e=Cur[p];~e;e=Last[e])if(Flow[e]&&Dist[To[e]]==Dist[p]+1&&dfs(To[e],t))
return Flow[e]=false,Flow[e^1]=true;
return false;
}
uint run(uint p,uint t)
{
uint ans=0;
while(bfs(p,t))for(uint e=End[p];~e;e=Last[e])if(Flow[e]&&dfs(To[e],t))Flow[e]=false,ans++;
return ans;
}
}
int main()
{
#ifdef MYEE
freopen("QAQ.in","r",stdin);
freopen("QAQ.out","w",stdout);
#endif
uint a,b,m;scanf("%u%u%u",&a,&b,&m),Dinic::build(a+b+2);
for(uint i=0;i<a;i++)Dinic::insert(a+b,i);
for(uint i=0;i<b;i++)Dinic::insert(a+i,a+b+1);
while(m--){uint u,v;scanf("%u%u",&u,&v),Dinic::insert(u,a+v);}
printf("%u\n",Dinic::run(a+b,a+b+1));
for(uint e=Dinic::End[a+b];~e;e=Dinic::Last[e])if(!Dinic::Flow[e])
for(uint e2=Dinic::End[Dinic::To[e]];~e2;e2=Dinic::Last[e2])if(Dinic::Flow[e2^1])
printf("%u %u\n",Dinic::To[e],Dinic::To[e2]-a);
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...