//Place your snippets for cpp here. Each snippet is defined under a snippet name and has a prefix, body and 
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
// same ids are connected.
// prefix 的格式要求是 acm-[一级标题编号].[二级标题编号][该代码片段的英文简称]
// description 的格式要求是 "插入 [该代码片段的中文名]"

{
    "最小费用最大流": {
        "prefix": "acm-3.5EK+SPFA",
        "body": [
            "#include<algorithm>",
            "#include<cstdio>",
            "#include<queue>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=5005,M=5e4+5,inf=2e9;",
            "int x,y,z,w,n,m,s,t,st,ed;",
            "inline void in(Re &x){",
            "    int f=0;x=0;char c=getchar();",
            "    while(c<'0'||c>'9')f|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=f?-x:x;",
            "}",
            "struct MCMF{",
            "\tint o,h,t,cyf[N],pan[N],pre[N],dis[N],head[N];LL mincost,maxflow;",
            "\tMCMF(){o=1;}",
            "\tstruct QAQ{int w,to,next,flow;}a[M<<1];queue<int>Q;",
            "\tinline void add_(Re x,Re y,Re flow,Re w){a[++o].w=w,a[o].to=y,a[o].flow=flow,a[o].next=head[x],head[x]=o;}",
            "\tinline void add(Re a,Re b,Re flow,Re w){add_(a,b,flow,w),add_(b,a,0,-w);}",
            "\tinline int SPFA(Re st,Re ed){",
            "\t\tfor(Re i=0;i<=ed;++i)dis[i]=inf,pan[i]=0;",
            "\t\tQ.push(st),pan[st]=1,dis[st]=0,cyf[st]=inf;",
            "\t\twhile(!Q.empty()){",
            "\t\t\tRe x=Q.front();Q.pop();pan[x]=0;",
            "\t\t\tfor(Re i=head[x],to;i;i=a[i].next)",
            "\t\t\t\tif(a[i].flow&&dis[to=a[i].to]>dis[x]+a[i].w){",
            "\t\t\t\t\tdis[to]=dis[x]+a[i].w,pre[to]=i;",
            "\t\t\t\t\tcyf[to]=min(cyf[x],a[i].flow);",
            "\t\t\t\t\tif(!pan[to])pan[to]=1,Q.push(to);",
            "\t\t\t\t}",
            "\t\t}",
            "\t\treturn dis[ed]!=inf;",
            "\t}",
            "\tinline void EK(Re st,Re ed){",
            "\t\twhile(SPFA(st,ed)){",
            "\t\t\tRe x=ed;maxflow+=cyf[ed],mincost+=(LL)cyf[ed]*dis[ed];",
            "\t\t\twhile(x!=st){",
            "\t\t\t\tRe i=pre[x];",
            "\t\t\t\ta[i].flow-=cyf[ed];",
            "\t\t\t\ta[i^1].flow+=cyf[ed];",
            "\t\t\t\tx=a[i^1].to;",
            "\t\t\t}",
            "\t\t}",
            "\t}",
            "}T1;",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),in(m),in(s),in(t),st=n+1,ed=st+1;",
            "\twhile(m--)in(x),in(y),in(z),in(w),T1.add(x,y,z,w);",
            "\tT1.add(st,s,inf,0),T1.add(t,ed,inf,0),T1.EK(st,ed);",
            "\tprintf(\"%lld %lld\\n\",T1.maxflow,T1.mincost);",
            "}",
            ""
        ],
        "description": "插入 最小费用最大流"
    }
}