萌新刚学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 蒟蒻lxy @ 2018-12-18 17:59:58

萌新刚学OI


by King_of_gamers @ 2018-12-18 18:00:04

我也看不懂


by StudyingFather @ 2018-12-18 18:00:42

我也看不懂


by jc2018 @ 2018-12-18 18:03:00

编译出错


by wxy_god @ 2018-12-18 18:11:32

emm...你是来正经的做题的吗


by 一扶苏一 @ 2018-12-18 18:17:17

炫技右转灌水区


by 小粉兔 @ 2018-12-18 18:21:48

炫技右转灌水区


by RiverFun @ 2018-12-18 18:26:14

炫技右转灌水区


by CreeperLordVader @ 2018-12-18 18:26:17

别装啦


by yzhang @ 2018-12-18 18:37:23

format了解一下


| 下一页