QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#342419 | #898. 二分图最大匹配 | shuopihua# | RE | 0ms | 0kb | C++14 | 1.9kb | 2024-03-01 11:18:13 | 2024-03-01 11:18:14 |
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define int long long
using namespace std;
int n,m,cnt=1;
int h[200005];
int cur[200005];
int dep[200005];
bool mp[200005];
struct node{int v,nxt,c;}edge[400005];
inline void addedge(int u,int v,int c){
edge[++cnt]={v,h[u],c};
h[u]=cnt;
edge[++cnt]={u,h[v],0};
h[v]=cnt;
return ;
}
inline bool bfs(int S,int T){
memset(dep,-1,sizeof(dep));
dep[S]=0;
queue <int> q;
q.push(S);
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=h[u];i;i=edge[i].nxt){
int v=edge[i].v;
if(edge[i].c&&dep[v]==-1){
dep[v]=dep[u]+1;
q.push(v);
}
}
}
return (dep[T]!=-1);
}
inline int dfs(int u,int T,int flow){
if(u==T||!flow) return flow;
int res=0;
mp[u]=1;
for(int i=cur[u];i;i=edge[i].nxt){
cur[u]=i;
int v=edge[i].v;
if(mp[v]||!edge[i].c||dep[v]!=dep[u]+1) continue;
int d=dfs(v,T,min(flow,edge[i].c));
res+=d;
edge[i].c-=d;
edge[i^1].c+=d;
flow-=d;
}
mp[u]=0;
return res;
}
inline int Dinic(int S,int T){
int f=0;
while(bfs(S,T)){
for(int i=1;i<=n;i++) cur[i]=h[i];
f+=dfs(S,T,1e18);
}
return f;
}
inline void in(int &n){
n=0;
char c=getchar();
while(c<'0' || c>'9') c=getchar();
while(c>='0'&&c<='9') n=n*10+c-'0',c=getchar();
return ;
}
signed main(){
int L,R;
in(L),in(R),in(m);
int s=L+R+1,t=s+1;
n=t;
for(int i=1;i<=m;i++){
int u,v;
in(u),in(v);
u++,v++;
v+=L;
addedge(u,v,1);
}
for(int i=1;i<=L;i++) addedge(s,i,1);
for(int i=L+1;i<=L+R;i++) addedge(i,t,1);
printf("%lld\n",Dinic(s,t));
for(int i=h[s];i;i=edge[i].nxt){
int v=edge[i].v;
if(edge[i].c==0){
printf("%lld ",v-1);
for(int j=h[v];j;j=edge[j].nxt){
int vv=edge[j].v;
if(edge[j].c==0&&vv<=L+R){
printf("%lld\n",vv-L-1);
puts("");
break;
}
}
}
}
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...