//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 的格式要求是 "插入 [该代码片段的中文名]"

{
    "最大流  (n m^2)": {
        "prefix": "acm-3.5EK",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<queue>",
            "#define Re register int",
            "using namespace std;",
            "const int N=1e4+3,M=1e5+3,inf=2e9;",
            "int x,y,z,o=1,n,m,h,t,st,ed,Q[N],cyf[N],pan[N],pre[N],head[N];long long maxflow; ",
            "struct QAQ{int to,next,flow;}a[M<<1];",
            "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;",
            "}",
            "inline void add(Re x,Re y,Re z){a[++o].flow=z,a[o].to=y,a[o].next=head[x],head[x]=o;}",
            "inline int bfs(Re st,Re ed){",
            "\tfor(Re i=0;i<=n;++i)pan[i]=0;",
            "\th=1,t=0,pan[st]=1,Q[++t]=st,cyf[st]=inf;",
            "\twhile(h<=t){",
            "\t\tRe x=Q[h++];",
            "\t\tfor(Re i=head[x],to;i;i=a[i].next)",
            "\t\t\tif(a[i].flow&&!pan[to=a[i].to]){",
            "\t\t\t\tcyf[to]=min(cyf[x],a[i].flow);",
            "\t\t\t\tQ[++t]=to,pre[to]=i,pan[to]=1;",
            "\t\t\t\tif(to==ed)return 1;",
            "\t\t\t}",
            "\t}",
            "\treturn 0;",
            "}",
            "inline void EK(Re st,Re ed){",
            "\twhile(bfs(st,ed)==1){",
            "\t\tRe x=ed;maxflow+=cyf[ed];",
            "\t\twhile(x!=st){",
            "\t\t\tRe i=pre[x];",
            "\t\t\ta[i].flow-=cyf[ed];",
            "\t\t\ta[i^1].flow+=cyf[ed];",
            "\t\t\tx=a[i^1].to;",
            "\t\t}",
            "\t}",
            "}",
            "int main(){",
            "\tin(n),in(m),in(st),in(ed);",
            "\twhile(m--)in(x),in(y),in(z),add(x,y,z),add(y,x,0);",
            "\tEK(st,ed);",
            "\tprintf(\"%lld\",maxflow);",
            "}",
            ""
        ],
        "description": "插入 最大流  (n m^2)"
    }
}