QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#670922 | #898. 二分图最大匹配 | yhddd | RE | 0ms | 0kb | C++20 | 1.9kb | 2024-10-24 08:49:08 | 2024-10-24 08:49:09 |
answer
#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=200010;
const int inf=1e18;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
return x*f;
}
bool Mbe;
int n,m,k;
struct nd{
int nxt,to,w;
}e[maxn<<1];
int head[maxn],tot=1,s,t;
void add(int u,int v,int w){
e[++tot]={head[u],v,w};head[u]=tot;
e[++tot]={head[v],u,0};head[v]=tot;
}
int rad[maxn],dis[maxn];
queue<int> q;
bool bfs(){
for(int i=1;i<=t;i++)rad[i]=head[i],dis[i]=0;
dis[s]=1;q.push(s);
while(!q.empty()){
int u=q.front();q.pop();
for(int i=head[u];i;i=e[i].nxt){
int v=e[i].to;
if(!dis[v]&&e[i].w)dis[v]=dis[u]+1,q.push(v);
}
}
return dis[t];
}
int dfs(int u,int res){
if(u==t)return res;
int cnt=0;
for(int i=rad[u];i;i=e[i].nxt){
int v=e[i].to;rad[u]=i;
if(dis[v]==dis[u]+1&&e[i].w){
int out=dfs(v,min(e[i].w,res));
e[i].w-=out;e[i^1].w+=out;
cnt+=out;res-=out;
if(!res)break;
}
}
return cnt;
}
void work(){
n=read();m=read();k=read();s=n+m+1,t=n+m+2;
for(int i=1;i<=k;i++){
int u=read()+1,v=read()+1;
add(u,v+n,1);
}
for(int i=1;i<=n;i++)add(s,i,1);
for(int i=1;i<=m;i++)add(i+n,t,1);
int flow=0;while(bfs())flow+=dfs(s,inf);
printf("%lld\n",flow);
for(int i=2;i<=2*k;i+=2)if(!e[i].w){
int u=e[i^1].to,v=e[i].to;
printf("%lld %lld\n",u-1,v-n-1);
}
}
// \
444
bool Med;
int T;
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
T=1;
while(T--)work();
}
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...