//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.2Prim n^2",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define Re register int",
            "using namespace std;",
            "const int N=5003,M=2e5+3,inf=2e9;",
            "int n,x,y,z,T,ans,pan[N],dis[N],a[N][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 Prim(){",
            "\tfor(Re i=0;i<=n;++i)dis[i]=inf;",
            "\tRe t=0;dis[1]=0;",
            "\tfor(Re i=1;i<=n&&t<n;++i){",
            "\t\tRe w=0;",
            "\t\tfor(Re j=1;j<=n;++j)if(!pan[j]&&dis[j]<dis[w])w=j;",
            "\t\tpan[w]=1,ans+=dis[w],++t;",
            "\t\tfor(Re j=1;j<=n;++j)if(!pan[j])dis[j]=min(dis[j],a[w][j]);",
            "\t}",
            "}",
            "int main(){",
            "\tin(n),in(T);",
            "\tmemset(a,127,sizeof(a));",
            "\twhile(T--)in(x),in(y),in(z),a[x][y]=a[y][x]=min(a[x][y],z);",
            "\tPrim();",
            "\tprintf(\"%d\\n\",ans);",
            "}",
            ""
        ],
        "description": "插入 最小生成树"
    }
}