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

{
    "2-SAT": {
        "prefix": "acm-3.3kosaraju",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define Re register int",
            "const int N=2e6+3,M=2e6+3;",
            "int n,m,mm,p1,p2,x1,x2,Q_o,X[M],Y[M],ip[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;",
            "}",
            "struct Kosaraju{",
            "\tint o,ndfn_o,nQ[N],pan[N],head[N];",
            "\tstruct QAQ{int x,to,next;}a[M];",
            "\tinline void add(Re x,Re y){a[++o].x=x,a[o].to=y,a[o].next=head[x],head[x]=o;}",
            "\tinline void dfs1(Re x){",
            "\t\tpan[x]=1;",
            "\t\tfor(Re i=head[x];i;i=a[i].next)if(!pan[a[i].to])dfs1(a[i].to);",
            "\t\tnQ[++ndfn_o]=x;",
            "\t}",
            "\tinline void dfs2(Re x){",
            "\t\tip[x]=Q_o;",
            "\t\tfor(Re i=head[x];i;i=a[i].next)if(!ip[a[i].to])dfs2(a[i].to);",
            "\t}",
            "\tinline void kosaraju(){",
            "\t\tfor(Re i=1;i<=m;++i)add(X[i],Y[i]);",
            "\t\tfor(Re i=1;i<=2*n;++i)if(!pan[i])dfs1(i);",
            "\t\tmemset(head,0,sizeof(head));",
            "\t\tmemset(pan,0,sizeof(pan));",
            "\t\tmemset(a,0,sizeof(a));o=0;",
            "\t\tfor(Re i=1;i<=m;++i)add(Y[i],X[i]);",
            "\t\tfor(Re i=ndfn_o;i;--i)if(!ip[nQ[i]])++Q_o,dfs2(nQ[i]);",
            "\t}",
            "}T1;",
            "int main(){",
            "\tin(n),in(mm);",
            "\twhile(mm--)in(p1),in(x1),in(p2),in(x2),X[++m]=p1+(x1^1)*n,Y[m]=p2+x2*n,X[++m]=p2+(x2^1)*n,Y[m]=p1+x1*n;",
            "\tT1.kosaraju();",
            "\tfor(Re i=1;i<=n;++i)if(ip[i]==ip[i+n])return !printf(\"IMPOSSIBLE\");",
            "\tputs(\"POSSIBLE\");",
            "\tfor(Re i=1;i<=n;++i)printf(\"%d \",ip[i]<ip[i+n]);",
            "}",
            ""
        ],
        "description": "插入 2-SAT"
    }
}