//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",
        "body": [
            "#include<algorithm>",
            "#include<cstdio>",
            "#include<queue>",
            "#define Re register int",
            "using namespace std;",
            "const int N=5003,M=2e5+3,inf=2e9;",
            "int x,y,z,n,m,o,ans,pan[N],dis[N],head[N];",
            "struct QAQ{int w,to,next;}a[M<<1];",
            "struct QWQ{int x,d;inline bool operator<(QWQ o)const{return d>o.d;};};",
            "priority_queue<QWQ>Q;",
            "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 add(Re x,Re y,Re z){a[++o].w=z,a[o].to=y,a[o].next=head[x],head[x]=o;}",
            "inline void Prim(){",
            "\tfor(Re i=0;i<=n;++i)pan[i]=0,dis[i]=inf;",
            "\tRe t=0;Q.push((QWQ){1,dis[1]=0});",
            "\twhile(!Q.empty()&t<n){",
            "\t\tRe x=Q.top().x;Q.pop();",
            "\t\tif(pan[x])continue;",
            "\t\tpan[x]=1,++t,ans+=dis[x];",
            "\t\tfor(Re i=head[x],to;i;i=a[i].next)",
            "\t\t\tif(dis[to=a[i].to]>a[i].w)Q.push((QWQ){to,dis[to]=a[i].w});",
            "\t}",
            "}",
            "int main(){",
            "\tin(n),in(m);",
            "\twhile(m--)in(x),in(y),in(z),add(x,y,z),add(y,x,z);",
            "\tPrim();",
            "\tprintf(\"%d\",ans);",
            "}",
            ""
        ],
        "description": "插入 最小生成树"
    }
}