QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479877#898. 二分图最大匹配Kalenist#WA 18ms13460kbC++142.0kb2024-07-15 21:29:472024-07-15 21:29:48

Judging History

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

  • [2024-07-15 21:29:48]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:13460kb
  • [2024-07-15 21:29:47]
  • 提交

answer

#include<bits/stdc++.h>
#define N 200010
#define inf 0x3f3f3f3f
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define Edge(i,x) for(register int i=head[x],to=e[i].t;i;i=e[i].nx,to=e[i].t)
#define EDge(i,x) for(register int i=lnk[x],to=e[i].t;i;i=e[i].nx,to=e[i].t)
using namespace std;
int head[N],x[N],y[N];
int lnk[N],num=1,dist[N],id[N];
bool exist[N],vis[N];
struct E{int nx,t,cap;}e[N<<1];
queue<int> q;
inline void add(int f,int t,int c){e[++num]=(E){head[f],t,c};head[f]=num;}
inline void bio_add(int f,int t,int c){add(f,t,c),add(t,f,0);}
inline int read()
{
    register int x=0,c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x;
}

inline bool BFS(int st,int en)
{
    For(i,0,en) dist[i]=-1,lnk[i]=head[i];
    dist[st]=0,q.push(st);
    while(!q.empty())
    {
        int k=q.front();q.pop();
        Edge(i,k) if(e[i].cap && dist[to] == -1)
            dist[to]=dist[k]+1,q.push(to);
    } 
    return dist[en]!=-1;
}

inline int dinic(int x,int t,int rest)
{
    if(x == t || !rest) return rest;
    int res=0;vis[x]=true;
    EDge(i,x)
    {
        lnk[x]=i;
	    if(!vis[to] && e[i].cap && dist[to] == dist[x]+1)
	    {
            int get=dinic(to,t,min(e[i].cap,rest-res));
            if(!get) continue;
	        e[i].cap-=get,e[i^1].cap+=get,res+=get;
	        if(res == rest) break;
	    }
    }vis[x]=false;
    return res;
}

inline int max_flow(int st,int en)
{
    int ans=0;
    while(BFS(st,en))
    {
        int nw=dinic(st,en,inf);
	    while(nw) ans+=nw,nw=dinic(st,en,inf);
    }
    return ans;
}

int main()
{
    int L=read(),R=read(),m=read();
    int s=0,t=L+R+1;
    For(i,1,L) bio_add(s,i,1);
    For(i,1,R) bio_add(L+i,t,1);
    For(i,1,m)
    {
        x[i]=read()+1,y[i]=read()+1;
	    bio_add(x[i],L+y[i],1),id[i]=num;
    }printf("%d\n",max_flow(s,t));
    For(i,1,m) if(e[id[i]].cap) printf("%d %d\n",x[i]-1,y[i]-1);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 18ms
memory: 13460kb

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:

0
301241 424308
94426 82724
145373 144055
421816 572520
106119 168155
559974 577844
25976 50058
560080 454050
602446 610368
90219 70279
185800 171466
371601 342933
207101 255987
138917 145103
551326 545594
479408 503642
38884 97237
680852 223593
146724 193517
548384 456510
1526 98211
153505 198302
5...

result:

wrong answer # of Matching is differ - expected: '100000', found '0'