QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#479609 | #898. 二分图最大匹配 | Justin# | TL | 0ms | 0kb | C++14 | 1.2kb | 2024-07-15 19:19:50 | 2024-07-15 19:19:51 |
answer
#include<bits/stdc++.h>
const int N=2e5+5,M=4e5+5,inf=1e9;
int n0,n1,m,S,T;
struct Edge{
int to,nxt,flow;
}e[M*2];
int hd[N],cur[N],gap[N],dis[N],pe=1;
void Add_Edge(int u,int v,int fl,bool T=true){
e[++pe]={v,hd[u],fl},hd[u]=pe;
if(T) Add_Edge(v,u,0,false);
}
int ISAP(int u,int lim){
if(u==T) return lim;
int res=0;
for(int &i=cur[u];i;i=e[i].nxt){
int v=e[i].to;
if(e[i].flow&&dis[u]==dis[v]+1){
int det=ISAP(v,std::min(lim,e[i].flow));
e[i].flow-=det,e[i^1].flow+=det;
lim-=det,res+=det;
if(!lim) return res;
}
}
cur[u]=hd[u];
if(!--gap[dis[u]]) dis[S]=T+1;
++gap[++dis[u]];
return res;
}
int main(){
// return 0;
scanf("%d%d%d",&n0,&n1,&m),S=n0+n1+1,T=S+1;
for(int i=1;i<=m;++i){
int u,v; scanf("%d%d",&u,&v);
++u,++v,Add_Edge(u,n0+v,1);
}
for(int i=1;i<=n0;++i) Add_Edge(S,i,1);
for(int i=1;i<=n1;++i) Add_Edge(n0+i,T,1);
int res=0;
while(dis[S]<=T) res+=ISAP(S,inf);
printf("%d\n",res);
return 0;
for(int i=1;i<=m;++i)
if(!e[i<<1].flow) printf("%d %d\n",e[i<<1|1].to-1,e[i<<1].to-n0-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...