QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#480497 | #898. 二分图最大匹配 | wdnmdwrnmmp# | RE | 0ms | 0kb | C++14 | 2.0kb | 2024-07-16 16:09:45 | 2024-07-16 16:09:46 |
answer
#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef vector<int> vi;
typedef pair<int,int> pi;
namespace flow{
const int N=2e5+5, M=2e5+5, inf=1e9;
int n,m=2,S,T;
int bg[N];
array<int,3> E[M*2];
void link(int u,int v){
E[m]={v,1,bg[u]}; bg[u]=m++;
E[m]={u,0,bg[v]}; bg[v]=m++;
}
int dis[N], cur[N];
int Q[N], head, tail;
bool bfs(){
fill(dis, dis+n+1, -1);
head=tail=1, Q[1]=S;
while(head<=tail){
int u=Q[head++];
for(int id=bg[u]; id; id=E[id][2]){
int v=E[id][0], w=E[id][1];
if(w && dis[v]==-1){
dis[v]=dis[u]+1;
cur[v]=bg[v];
if(v==T){
return true;
}
Q[++tail]=v;
}
}
}
return false;
}
int dfs(int u,int rst){
if(u==S){
return rst;
}
int pre=rst;
// cout<<"?"<<u<<' '<<rst<<' '<<cur[u]<<endl;
for(int &id=cur[u]; id; id=E[id][2]){
int v=E[id][0], w=E[id^1][1];
if(dis[v]+1==dis[u] && w){
int f=dfs(v, min(rst, w));
E[id][1]+= f, E[id^1][1]-= f, rst-= f;
if(!rst){
break;
}
}
}
return pre-rst;
}
int dinic(){
int res=0;
while(bfs()){
res+= dfs(T, inf);
}
return res;
}
void output(int _L){
for(int id=bg[S]; id; id=E[id][2]){
int v=E[id][0], w=E[id][1];
if(w==0){
for(int _id=bg[v]; _id; _id=E[_id][2]){
if(E[_id][1]==0){
cout<< v-1 <<' '<< E[_id][0]-_L-1 <<'\n';
}
}
}
}
}
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int L,R,m; cin>>L>>R>>m;
flow::n=L+R+2, flow::S=L+R+1, flow::T=L+R+2;
rep(i,1,L){
flow::link(flow::S, i);
}
rep(i,1,R){
flow::link(L+i, flow::T);
}
rep(i,1,m){
int u,v; cin>>u>>v;
u++, v++;
flow::link(u, L+v);
}
int ans=flow::dinic();
cout<< ans <<'\n';
flow::output(L);
}
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...