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

{
    "最大流  (m n^2)": {
        "prefix": "acm-3.5Dinic+多路增广+当前弧",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#include<queue>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=1e4+5,M=1e5+5,inf=2147483647;",
            "int x,y,z,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 Dinic{",
            "\tint o,h,t,Q[N],dis[N],cur[N],head[N];LL maxflow;",
            "\tDinic(){o=1;}",
            "\tstruct QAQ{int to,next,flow;}a[M<<1];",
            "\tinline void add_(Re x,Re y,Re flow){a[++o].to=y,a[o].flow=flow,a[o].next=head[x],head[x]=o;}",
            "\tinline void add(Re x,Re y,Re flow){add_(x,y,flow),add_(y,x,0);}",
            "\tinline int bfs(Re st,Re ed){",
            "\t\tfor(Re i=0;i<=ed;++i)dis[i]=0,cur[i]=head[i];",
            "\t\th=1,t=0,Q[++t]=st,dis[st]=1;",
            "\t\twhile(h<=t){",
            "\t\t\tRe x=Q[h++];",
            "\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]){",
            "\t\t\t\t\tdis[to]=dis[x]+1,Q[++t]=to;",
            "\t\t\t\t\tif(to==ed)return 1;",
            "\t\t\t\t}",
            "\t\t}",
            "\t\treturn 0;",
            "\t}",
            "\tinline int dfs(Re x,Re flow){",
            "\t\tif(x==ed||!flow)return flow;",
            "\t\tRe tmp=0,to,f;",
            "\t\tfor(Re i=cur[x];i;i=a[i].next){",
            "\t\t\tcur[x]=i;",
            "\t\t\tif(dis[to=a[i].to]==dis[x]+1&&(f=dfs(to,min(flow-tmp,a[i].flow)))){",
            "\t\t\t\ta[i].flow-=f,a[i^1].flow+=f,tmp+=f;",
            "\t\t\t\tif(flow==tmp)break;",
            "\t\t\t}",
            "\t\t}",
            "\t\treturn tmp;",
            "\t}",
            "\tinline void dinic(Re st,Re ed){while(bfs(st,ed))maxflow+=dfs(st,inf);}",
            "}T1;",
            "int main(){",
            "    in(n),in(m),in(s),in(t),st=n+1,ed=st+1;",
            "    while(m--)in(x),in(y),in(z),T1.add(x,y,z);",
            "    T1.add(st,s,inf),T1.add(t,ed,inf),T1.dinic(st,ed);",
            "    printf(\"%lld\",T1.maxflow);",
            "}",
            ""
        ],
        "description": "插入 最大流  (m n^2)"
    }
}