//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-2.4并查集实战",
        "body": [
            "#include<cstdio>",
            "#include<cstring>",
            "#include<iostream>",
            "using namespace std;",
            "int fa[1001],n,k;",
            "struct sakura{int u,v,next;}sak[4001];",
            "int st[1001],tot=0;",
            "int p[1001],pp[1001];",
            "",
            "void add(int x,int y){",
            "    tot++;",
            "    sak[tot].u=x;",
            "    sak[tot].v=y;",
            "    sak[tot].next=st[x];",
            "    st[x]=tot;",
            "}",
            "",
            "int find(int x){",
            "    if (fa[x]!=x)",
            "       fa[x]=find(fa[x]);",
            "    return fa[x];",
            "}",
            "",
            "void unionn(int r1,int r2){",
            "    fa[r1]=r2;",
            "}",
            "",
            "void doit(){",
            "    int i,j;",
            "    for (i=n-1;i>=1;i--){",
            "    \tpp[i]=1;",
            "        for (j=st[i];j;j=sak[j].next){",
            "            if (pp[sak[j].v]){",
            "               \tint r1=find(sak[j].u);",
            "               \tint r2=find(sak[j].v);",
            "               \tif (r1!=r2){",
            "                  \tunionn(r1,r2);",
            "                  \tp[r1]+=p[r2]; ",
            "                  \tp[r2]=p[r1];",
            "            \t}",
            "            }",
            "        }",
            "        if (p[find(i)]>(n+1)/2){",
            "            printf(\"%d\",i);",
            "        }",
            "    }",
            "}",
            "",
            "int main(){",
            "    scanf(\"%d\",&n);",
            "    pp[n]=1;",
            "    for (int i=1;i<=n;i++){",
            "        scanf(\"%d\",&k);",
            "        fa[i]=i;",
            "        p[i]=1; ",
            "        for (int j=1;j<=k;j++){",
            "            int x;",
            "            scanf(\"%d\",&x);",
            "            add(i,x);",
            "        }",
            "    }",
            "    doit();",
            "    return 0;",
            "}",
            ""
        ],
        "description": "插入 打击罪犯"
    }
}