QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#479664#898. 二分图最大匹配grass8cow#RE 0ms0kbC++171.3kb2024-07-15 19:58:192024-07-15 19:58:19

Judging History

你现在查看的是最新测评结果

  • [2024-07-15 19:58:19]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-07-15 19:58:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int d[100100];
int to[100100],nxt[101000],cn=1,hd[101000],S,T;
int flow[100100];
void ad(int u,int v,int w){
    to[++cn]=v,flow[cn]=w,nxt[cn]=hd[u],hd[u]=cn;
    to[++cn]=u,flow[cn]=0,nxt[cn]=hd[v],hd[v]=cn;
}
const int I=1e9;
bool bfs(){
    for(int i=1;i<=T;i++)d[i]=0;
    queue<int>q;q.push(S),d[S]=1;
    while(!q.empty()){
        int u=q.front();q.pop();
        for(int i=hd[u];i;i=nxt[i])if(flow[i]&&!d[to[i]])
            d[to[i]]=d[u]+1,q.push(to[i]);
    }
    return d[T]>0;
}
int dfs(int u,int in){
    if(u==T)return in;int out=0;
    for(int i=hd[u];i&&in;i=nxt[i])if(flow[i]&&d[to[i]]==d[u]+1){
        int e=dfs(to[i],min(in,flow[i]));
        flow[i]-=e,flow[i^1]+=e;
        in-=e,out+=e;
    }
    if(!out)d[u]=0;
    return out;
}
int n1,n2,m;
int main(){
    scanf("%d%d%d",&n1,&n2,&m);S=n1+n2+1,T=S+1;
    for(int i=1,u,v;i<=m;i++)
        scanf("%d%d",&u,&v),u++,v++,ad(u,v+n1,1);
    for(int i=1;i<=n1;i++)ad(S,i,1);
    for(int i=1;i<=n2;i++)ad(i+n1,T,1);
    int ans=0;
    while(bfs())ans+=dfs(S,I);printf("%d\n",ans);
    for(int i=1;i<=n1;i++)
        for(int j=hd[i];j;j=nxt[j])if(to[j]>n1&&to[j]<S&&!flow[j])
        printf("%d %d\n",i-1,to[j]-1-n1);
    return 0;
}

詳細信息

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...

output:


result: