//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-4.3dfs",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define Re register int",
            "using namespace std;",
            "const int N=1e4+3,M=3e5+3;",
            "int n,m,x,y,o,head[N];",
            "struct QAQ{int w,to,next;}a[N<<1];",
            "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){",
            "\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;",
            "}",
            "struct Tree_Diam_DFS{",
            "\tint cur,dis[N];",
            "\tinline void dfs(Re x,Re fa){",
            "\t\tif(dis[x]>dis[cur])cur=x;",
            "\t\tfor(Re i=head[x],to;i;i=a[i].next)",
            "\t\t\tif((to=a[i].to)!=fa)dis[to]=dis[x]+a[i].w,dfs(to,x);",
            "\t}",
            "\tinline int sakura(){",
            "\t\tdfs(1,0);",
            "\t\tmemset(dis,0,sizeof(dis));",
            "\t\tdfs(cur,0);",
            "\t\treturn dis[cur];",
            "\t}",
            "}T1;",
            "int main(){",
            "\tin(n),m=n-1;",
            "    while(m--)in(x),in(y),add(x,y,1),add(y,x,1);",
            "    printf(\"%d\\n\",T1.sakura());",
            "}",
            ""
        ],
        "description": "插入 树的直径"
    }
}