//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.1SPFA",
        "body": [
            "#include<algorithm>",
            "#include<cstdio>",
            "#include<queue>",
            "#define Re register int",
            "using namespace std;",
            "const int N=5003,M=1e5+3,inf=1e9;",
            "int n,m,x,y,z,o,pan[N],head[N],dis[N][2];",
            "struct QAQ{int w,to,next;}a[M<<1];queue<int>Q;",
            "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 in(Re &x){",
            "    Re fu=0;x=0;char ch=getchar();",
            "    while(ch<'0'||ch>'9')fu|=ch=='-',ch=getchar();",
            "    while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();",
            "    x=fu?-x:x;",
            "}",
            "inline void SPFA(Re st){",
            "    for(Re i=0;i<=n;++i)dis[i][0]=dis[i][1]=inf;",
            "    dis[st][0]=0,pan[st]=1,Q.push(st);",
            "    while(!Q.empty()){",
            "        Re x=Q.front();Q.pop();pan[x]=0;",
            "        for(Re i=head[x],to,tmp;i;i=a[i].next){",
            "            if(dis[to=a[i].to][0]>(tmp=dis[x][0]+a[i].w)){",
            "                dis[to][1]=dis[to][0];",
            "                dis[to][0]=tmp;",
            "                if(!pan[to])pan[to]=1,Q.push(to);",
            "            }",
            "            if(dis[to][1]>(tmp=dis[x][0]+a[i].w)&&tmp>dis[to][0]){",
            "                dis[to][1]=tmp;",
            "                if(!pan[to])pan[to]=1,Q.push(to);",
            "            }",
            "            if(dis[to][1]>(tmp=dis[x][1]+a[i].w)){",
            "                dis[to][1]=tmp;",
            "                if(!pan[to])pan[to]=1,Q.push(to);",
            "            }",
            "        }",
            "    }",
            "}",
            "int main(){",
            "    in(n),in(m);",
            "    while(m--)in(x),in(y),in(z),add(x,y,z),add(y,x,z);",
            "    SPFA(1);",
            "    printf(\"%d\\n\",dis[n][1]);",
            "}",
            ""
        ],
        "description": "插入 次短路"
    }
}