90分WA蒟蒻求助

P3376 【模板】网络最大流

liuyifan @ 2019-09-28 16:55:57

Rt.WA第3个点 TwT

// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define reg register
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
struct edge
{
    ll from,to,x,flow,pre;
}e[1000005];
queue<ll>q;
ll m,n,h[1000005],tot,pre[1000005],a[1000005],flow,s=1,t,x,y,z;
inline void clear(queue<ll>&q) 
{
    queue<ll>x;
    swap(x,q);
}
inline void addedge(ll from,ll to,ll x)
{
    tot++;
    e[tot].from=from;
    e[tot].to=to;
    e[tot].x=x;
    e[tot].flow=0;
    e[tot].pre=h[from];
    h[from]=tot;
}
int main()
{
    scanf("%lld%lld%lld%lld",&m,&n,&s,&t);
    for(reg ll i=1;i<=n;i++)
    {
        scanf("%lld%lld%lld",&x,&y,&z);
        addedge(x,y,z);
        addedge(y,x,0);
    }
    while(1)
    {
        memset(a,0,sizeof(a));
        clear(q);
        q.push(s);
        a[s]=inf;
        pre[s]=0;
        while(!q.empty())
        {
            reg ll u=q.front();
            q.pop();
            for(reg ll i=h[u];i;i=e[i].pre)
            {
                reg ll v=e[i].to;
                if(!a[v]&&e[i].x>e[i].flow)
                {
                    a[v]=min(a[u],e[i].x-e[i].flow);
                    pre[v]=i;
                    q.push(v);
                }
            }
            if(a[t])break;
        }
        if(!a[t])break;
        for(reg ll u=t;u!=s;u=e[pre[u]].from)
        {
            e[pre[u]].flow+=a[t];
            e[(pre[u]-1)^1+1].flow-=a[t];
        }
        flow+=a[t];
    }
    printf("%lld",flow);
    return 0;
}

by wubaiting2020 @ 2019-09-28 17:00:29

@liuyifan Orz


by wubaiting2020 @ 2019-09-28 17:00:38

@liuyifan QNDJR


by liuyifan @ 2019-09-28 17:08:39

@wubaiting2020 来改啊QwQ


by liuyifan @ 2019-09-28 17:08:57

@wubaiting2020 是兄弟就来砍我


|