//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 的格式要求是 "插入 [该代码片段的中文名]"

{
    "树的直径升级版 每个点可到的最远距离computer": {
        "prefix": "acm-4.3HDU",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define R register int",
            "using namespace std;",
            "int n,b,c,d,t,longson[10005],d1[10005],d2[10005],df[10005],head[10005];",
            "struct QAQ{int to,next,w;}a[20005];",
            "inline void add(int x,int y,int w){a[++t].to=y,a[t].w=w,a[t].next=head[x],head[x]=t;}",
            "inline void dfs(int x,int pa){",
            "\tfor(R i=head[x];i;i=a[i].next){",
            "\t\tR s,to=a[i].to;",
            "\t\tif(to==pa)continue;",
            "\t\tdfs(to,x);s=d1[to]+a[i].w;",
            "\t\tif(s>d1[x])d2[x]=d1[x],d1[x]=s,longson[x]=to;",
            "\t\telse d2[x]=max(d2[x],s);",
            "\t}",
            "}",
            "inline void dfsf(int x,int pa){",
            "\tfor(R i=head[x];i;i=a[i].next){",
            "\t\tR to=a[i].to;",
            "\t\tif(to==pa)continue;",
            "\t\tif(longson[x]==to)df[to]=a[i].w+max(d2[x],df[x]);",
            "\t\telse df[to]=a[i].w+max(d1[x],df[x]);",
            "\t\tdfsf(to,x);",
            "\t}",
            "}",
            "inline int sakura(){",
            "\twhile(~scanf(\"%d\",&n)){",
            "\t\tmemset(longson,0,sizeof(longson));",
            "\t\tmemset(head,0,sizeof(head));",
            "\t\tmemset(d1,0,sizeof(d1));",
            "\t\tmemset(d2,0,sizeof(d2));",
            "\t\tmemset(df,0,sizeof(df));",
            "\t\tmemset(a,0,sizeof(a));t=0;",
            "\t\tfor(R i=2;i<=n;i++){",
            "\t\t\tscanf(\"%d%d\",&b,&c);",
            "\t\t\tadd(i,b,c),add(b,i,c);",
            "\t\t}",
            "\t\tdfs(1,0);dfsf(1,0);",
            "\t\tfor(R i=1;i<=n;i++)printf(\"%d\\n\",max(d1[i],df[i]));",
            "\t}",
            "\treturn 0;",
            "}",
            "int QAQWQ=sakura();",
            "int main(){}",
            ""
        ],
        "description": "插入 树的直径升级版 每个点可到的最远距离computer"
    }
}