//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.2Kruscal",
        "body": [
            "#include<algorithm>",
            "#include<cstdio>",
            "#define Re register int",
            "using namespace std;",
            "const int N=5003,M=2e5+3;",
            "int n,m,ans,fa[N];",
            "struct QAQ{int x,y,w;inline bool operator<(const QAQ &O)const{return w<O.w;};}A[M];",
            "inline void in(Re &x){",
            "\tRe fu=0;x=0;char ch=getchar();",
            "\twhile(ch<'0'||ch>'9')fu|=ch=='-',ch=getchar();",
            "\twhile(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();",
            "\tx=fu?-x:x;",
            "}",
            "inline int find(Re x){return x==fa[x]?x:fa[x]=find(fa[x]);}",
            "int main(){",
            "\tin(n),in(m);",
            "\tfor(Re i=1;i<=n;++i)fa[i]=i;",
            "\tfor(Re i=1;i<=m;++i)in(A[i].x),in(A[i].y),in(A[i].w);",
            "\tsort(A+1,A+m+1);",
            "\tfor(Re i=1,t=0;i<=m&&t<n-1;++i){",
            "\t\tRe x=find(A[i].x),y=find(A[i].y);",
            "\t\tif(x!=y)++t,ans+=A[i].w,fa[x]=y;",
            "\t}",
            "\tprintf(\"%d\",ans);",
            "}",
            ""
        ],
        "description": "插入 最小生成树"
    }
}