//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.4sort+并查集",
        "body": [
            "#include<algorithm>",
            "#include<cstdlib>",
            "#include<cstdio>",
            "int g,i,j,n,m,p,x,y,c,ans,k,f[2010];",
            "struct QAQ{int l,r,w;}a[40010];",
            "inline int fi(int x){if(x!=f[x])f[x]=fi(f[x]);return f[x];}",
            "inline int cmp(const QAQ &a,const QAQ &b){return a.w<b.w;}",
            "int main(){",
            "    scanf(\"%d%d\",&n,&m);",
            "    for(i=1;i<=n;i++)f[i]=i;",
            "    for(i=1;i<=m;i++){",
            "        scanf(\"%d%d%d%d\",&p,&x,&y,&c);",
            "        if(p==1){ans+=c,f[fi(y)]=fi(x);}",
            "        else a[++g].l=x,a[g].r=y,a[g].w=c;",
            "    }",
            "    std::sort(a+1,a+g+1,cmp);",
            "    for(i=1;i<=g;i++){",
            "        x=fi(a[i].l),y=fi(a[i].r);",
            "        if(x!=y){",
            "            f[y]=x;k++;",
            "            ans+=a[i].w;",
            "        }",
            "    }",
            "    printf(\"%d\",ans);",
            "    return 0;",
            "}",
            ""
        ],
        "description": "插入 联络员"
    }
}