萌新刚学OI,看不懂自己的代码QWQ

P3376 【模板】网络最大流

Quank123Wip @ 2018-12-18 17:58:18

#include<bits/stdc++.h>
const int maxn=10000+10;const int maxm=(100000+10)*2;int n,m,s,t;int cnt=0;namespace FastInput{int Getint(void){int rtv;char c=getchar();while(!std::isdigit(c))c=std::getchar();while(std::isdigit(c))rtv=rtv*10+c-'0';return rtv;}long long GetLL(void){long long rtv;char c=getchar();while(!std::isdigit(c))c=std::getchar();while(std::isdigit(c))rtv=rtv*10+c-'0';return rtv;}}using FastInput::Getint;class Graph{private:struct Edge{int to,next,w;};public:int Head[maxn],Cur[maxn],Depth[maxn];Edge Edges[maxm];void __addE(int u,int v,int w){Edges[cnt]=(Edge){v,Head[u],w};Head[u]=cnt++;}void AddEdge(int u,int v,int w){__addE(u,v,w);__addE(v,u,0);}}P;inline bool BFS(void){std::memset(P.Depth,0x7f,sizeof(P.Depth));std::queue<int>q;for(int i=1;i<=n;i++)P.Cur[i]=P.Head[i];P.Depth[s]=0;q.push(s);while(!q.empty()){int now=q.front();q.pop();for(int i=P.Head[now];i!=-1;i=P.Edges[i].next){if(P.Depth[P.Edges[i].to]>1e9&&P.Edges[i].w){P.Depth[P.Edges[i].to]=P.Depth[now]+1;q.push(P.Edges[i].to);}}}return P.Depth[t]<1e9;}int DFS(int now,int MinFlow){if(now==t||!MinFlow)return MinFlow;int Flow=0,f;for(int i=P.Cur[now];i!=-1;i=P.Edges[i].next){P.Cur[now]=i;if(P.Depth[P.Edges[i].to]==P.Depth[now]+1&&(f=DFS(P.Edges[i].to,std::min(MinFlow,P.Edges[i].w)))){MinFlow-=f;Flow+=f;P.Edges[i].w-=f;P.Edges[i^1].w+=f;if(!MinFlow)break;}}return Flow;}int Dinic(void){int MaxFlow=0;while(BFS())while(int now=DFS(s,1e9))MaxFlow+=now;return MaxFlow;}int main(){scanf("%d%d%d%d",&n,&m,&s,&t);for(int i=0;i<maxn;i++)P.Head[i]=-1;for(int i=0;i<m;i++){int u,v,w;scanf("%d%d%d",&u,&v,&w);P.AddEdge(u,v,w);}std::printf("%d",Dinic());}

by memset0 @ 2018-12-18 18:45:29

@Quank123Wip 真会装逼


by Erusel @ 2018-12-18 18:47:25

Ctrl Shift A


by Erusel @ 2018-12-18 18:48:10

#include<bits/stdc++.h>
const int maxn=10000+10;
const int maxm=(100000+10)*2;
int n,m,s,t;
int cnt=0;
namespace FastInput {
    int Getint(void) {
        int rtv;
        char c=getchar();
        while(!std::isdigit(c))c=std::getchar();
        while(std::isdigit(c))rtv=rtv*10+c-'0';
        return rtv;
    } long long GetLL(void) {
        long long rtv;
        char c=getchar();
        while(!std::isdigit(c))c=std::getchar();
        while(std::isdigit(c))rtv=rtv*10+c-'0';
        return rtv;
    }
} using FastInput::Getint;
class Graph {
    private:
        struct Edge {
            int to,next,w;
        };
    public:
        int Head[maxn],Cur[maxn],Depth[maxn];
        Edge Edges[maxm];
        void __addE(int u,int v,int w) {
            Edges[cnt]=(Edge) {
                v,Head[u],w
            };
            Head[u]=cnt++;
        } void AddEdge(int u,int v,int w) {
            __addE(u,v,w);
            __addE(v,u,0);
        }
} P;
inline bool BFS(void) {
    std::memset(P.Depth,0x7f,sizeof(P.Depth));
    std::queue<int>q;
    for(int i=1; i<=n; i++)P.Cur[i]=P.Head[i];
    P.Depth[s]=0;
    q.push(s);
    while(!q.empty()) {
        int now=q.front();
        q.pop();
        for(int i=P.Head[now]; i!=-1; i=P.Edges[i].next) {
            if(P.Depth[P.Edges[i].to]>1e9&&P.Edges[i].w) {
                P.Depth[P.Edges[i].to]=P.Depth[now]+1;
                q.push(P.Edges[i].to);
            }
        }
    }
    return P.Depth[t]<1e9;
}
int DFS(int now,int MinFlow) {
    if(now==t||!MinFlow)return MinFlow;
    int Flow=0,f;
    for(int i=P.Cur[now]; i!=-1; i=P.Edges[i].next) {
        P.Cur[now]=i;
        if(P.Depth[P.Edges[i].to]==P.Depth[now]+1&&(f=DFS(P.Edges[i].to,std::min(MinFlow,P.Edges[i].w)))) {
            MinFlow-=f;
            Flow+=f;
            P.Edges[i].w-=f;
            P.Edges[i^1].w+=f;
            if(!MinFlow)break;
        }
    }
    return Flow;
}
int Dinic(void) {
    int MaxFlow=0;
    while(BFS())while(int now=DFS(s,1e9))MaxFlow+=now;
    return MaxFlow;
}
int main() {
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=0; i<maxn; i++)P.Head[i]=-1;
    for(int i=0; i<m; i++) {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        P.AddEdge(u,v,w);
    }
    std::printf("%d",Dinic());
}

by 逍遥_向尾喵 @ 2018-12-18 18:58:29

@yzhang 名字颜色真好


by Quank123Wip @ 2018-12-19 05:08:54

@Robinzh 请停止你的大括号不换行行为,正解clang-format


上一页 |