//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.5add_",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=4003,M=6e4+3,inf=2e9;",
            "int n,m,x,y,z,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];",
            "\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<=n;++i)dis[i]=0,cur[i]=head[i];",
            "\t\th=1,t=0,dis[st]=1,Q[++t]=st;",
            "\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}",
            "\tint Q_o,dfn_O,ip[N],dfn[N],low[N],pan[N];",
            "\tinline void tarjan(Re x){",
            "\t\tdfn[x]=low[x]=++dfn_O,Q[++t]=x,pan[x]=1;",
            "\t\tfor(Re i=head[x],to;i;i=a[i].next)",
            "\t\t\tif(a[i].flow){",
            "\t\t\t\tif(!dfn[to=a[i].to])tarjan(to),low[x]=min(low[x],low[to]);",
            "\t\t\t\telse if(pan[to])low[x]=min(low[x],dfn[to]);",
            "\t\t\t}",
            "\t\tif(dfn[x]==low[x]){",
            "\t\t\t++Q_o;",
            "\t\t\twhile(1){",
            "\t\t\t\tip[Q[t]]=Q_o,pan[Q[t]]=0;",
            "\t\t\t\tif(x==Q[t--])break;",
            "\t\t\t}",
            "\t\t}",
            "\t}",
            "\tinline void sakura(){",
            "\t\twhile(bfs(st,ed))dfs(st,inf);",
            "\t\tfor(Re i=1;i<=n;++i)if(!dfn[i])tarjan(i);",
            "\t\tfor(Re i=2;i<=o;i+=2)printf(\"%d %d\\n\",",
            "\t\t\t(!a[i].flow&&ip[a[i^1].to]!=ip[a[i].to]),",
            "\t\t\t(!a[i].flow&&ip[st]==ip[a[i^1].to]&&ip[a[i].to]==ip[ed]));",
            "\t}",
            "}T1;",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),in(m),in(st),in(ed),T1.o=1;",
            "\twhile(m--)in(x),in(y),in(z),T1.add(x,y,z);",
            "\tT1.sakura();",
            "}",
            ""
        ],
        "description": "插入 最小割可行边、必须边"
    }
}