QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#472917 | #898. 二分图最大匹配 | Purslane# | RE | 0ms | 0kb | C++20 | 1.6kb | 2024-07-11 20:20:13 | 2024-07-11 20:20:13 |
answer
#include<bits/stdc++.h>
#define int long long
#define ffor(i,a,b) for(int i=(a);i<=(b);i++)
#define roff(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
const int MAXN=100000+10,MAXM=1000000+10;
int L,R,m,s,t,ans,tmp,tot=1,hd[MAXN],cur[MAXN],dis[MAXN];
struct Edge {int to,nxt,w;}edge[MAXM<<1];
void add_edge(int u,int v,int w) {
edge[++tot]={v,hd[u],w},hd[u]=tot;
edge[++tot]={u,hd[v],0},hd[v]=tot;
return ;
}
int bfs(void) {
memset(dis,-1,sizeof(dis));
queue<int> q;
dis[s]=0,q.push(s);
while(!q.empty()) {
int u=q.front();
q.pop(),cur[u]=hd[u];
for(int i=hd[u];i;i=edge[i].nxt) {
int to=edge[i].to,w=edge[i].w;
if(!w||dis[to]!=-1) continue ;
dis[to]=dis[u]+1,q.push(to);
}
}
return dis[t]!=-1;
}
int dinic(int u,int mx) {
if(u==t) return mx;
int res=0;
for(int i=cur[u];i;i=edge[i].nxt,cur[u]=i) {
int to=edge[i].to,w=edge[i].w;
if(dis[to]!=dis[u]+1||!w) continue ;
int tmp=dinic(to,min(w,mx));
if(tmp) {
edge[i].w-=tmp,edge[i^1].w+=tmp,mx-=tmp,res+=tmp;
if(!mx) break ;
}
else dis[to]=-1;
}
return res;
}
signed main() {
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>L>>R>>m,s=0,t=L+R+1;
ffor(i,1,m) {
int u,v;
cin>>u>>v;
u++,v++,add_edge(u,v+L,1);
}
ffor(i,1,L) add_edge(s,i,1);
ffor(i,L+1,L+R) add_edge(i,t,1);
while(bfs()) while(dinic(s,1000000));
vector<pair<int,int>> ans;
ffor(u,1,L) for(int i=hd[u];i;i=edge[i].nxt) {
int to=edge[i].to,w=edge[i].w;
if(to>=L+1&&to<=L+R&&!w) ans.push_back({u-1,to-L-1});
}
cout<<ans.size()<<'\n';
for(auto pr:ans) cout<<pr.first<<' '<<pr.second<<'\n';
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...