//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.5Dinic",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define Re register int",
            "using namespace std;",
            "const int N=103,inf=2e9;",
            "int x,y,n,m,o=1,h,t,st,ed,ans,maxflow,Q[N],dis[N],head[N];",
            "struct QAQ{int to,next,flow;}a[N*N*2+N];",
            "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+2;++i)dis[i]=0;",
            "\th=1,t=0,dis[st]=1,Q[++t]=st;",
            "\twhile(h<=t){",
            "\t\tRe to,x=Q[h++];",
            "\t\tfor(Re i=head[x];i;i=a[i].next)",
            "\t\t\tif(a[i].flow&&!dis[to=a[i].to]){",
            "\t\t\t\tdis[to]=dis[x]+1,Q[++t]=to;",
            "\t\t\t\tif(to==ed)return 1;",
            "\t\t\t}",
            "\t}",
            "\treturn 0;",
            "}",
            "inline int dfs(Re x,Re flow){",
            "\tif(!flow||x==ed)return flow;",
            "\tRe tmp=0,to,f;",
            "\tfor(Re i=head[x];i;i=a[i].next)",
            "\t\tif(dis[to=a[i].to]==dis[x]+1&&(f=dfs(to,min(flow-tmp,a[i].flow)))){",
            "\t\t\ta[i].flow-=f,a[i^1].flow+=f,tmp+=f;",
            "\t\t\tif(flow==tmp)break;",
            "\t\t}",
            "\treturn tmp;",
            "}",
            "inline void Dinic(Re st,Re ed){",
            "\tRe flow=0;while(bfs(st,ed))while(flow=dfs(st,inf))maxflow+=flow;",
            "}",
            "int main(){",
            "\tin(m),in(n),st=n+1,ed=n+2;",
            "\twhile(1){",
            "\t\tin(x),in(y);",
            "\t\tif(x==-1)break;",
            "\t\tadd(x,y,1),add(y,x,0);",
            "\t}",
            "\tfor(Re i=1;i<=m;++i)add(st,i,1),add(i,st,0);",
            "\tfor(Re i=m+1;i<=n;++i)add(i,ed,1),add(ed,i,0);",
            "\tDinic(st,ed);",
            "\tprintf(\"%d\\n\",maxflow);",
            "\tfor(Re x=1;x<=m;++x)",
            "\t\tfor(Re i=head[x];i;i=a[i].next)",
            "\t\t\tif(!(i&1)&&a[i].to!=st&&!a[i].flow)printf(\"%d %d\\n\",x,a[i].to);",
            "}",
            ""
        ],
        "description": "插入 飞行员配对方案问题"
    }
}