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

{
    "Crash的文明世界": {
        "prefix": "acm-4.5树形dp",
        "body": [
            "#include<algorithm>",
            "#include<cstring>",
            "#include<cstdio>",
            "#define LL long long",
            "#define Re register int",
            "using namespace std;",
            "const int N=5e4+3,M=153,P=10007;",
            "int n,m,x,y,o,K,jc[M],fto[M],head[N],S[M][M],f[N][M],g[N][M];",
            "struct QAQ{int to,next;}a[N<<1];",
            "inline void add(Re x,Re y){a[++o].to=y,a[o].next=head[x],head[x]=o;}",
            "inline void in(Re &x){",
            "    int dp=0;x=0;char c=getchar();",
            "    while(c<'0'||c>'9')dp|=c=='-',c=getchar();",
            "    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();",
            "    x=dp?-x:x;",
            "}",
            "inline void dfs1(Re x,Re fa){",
            "\tf[x][0]=1;",
            "\tfor(Re i=head[x],to;i;i=a[i].next)",
            "\t\tif((to=a[i].to)!=fa){",
            "\t\t\tdfs1(to,x),(f[x][0]+=f[to][0])%=P;",
            "\t\t\tfor(Re j=1;j<=K;++j)(f[x][j]+=(f[to][j]+f[to][j-1])%P)%=P;",
            "\t\t}",
            "}",
            "inline void dfs2(Re x,Re fa){",
            "\tif(fa){",
            "\t\tfto[0]=(g[fa][0]+f[fa][0]-f[x][0]+P)%P;",
            "\t\tfor(Re j=1;j<=K;++j)fto[j]=(g[fa][j]+f[fa][j]-(f[x][j]+f[x][j-1])%P+P)%P;",
            "\t\tg[x][0]=fto[0];",
            "\t\tfor(Re j=1;j<=K;++j)g[x][j]=(fto[j]+fto[j-1])%P;",
            "\t}",
            "\tfor(Re i=head[x],to;i;i=a[i].next)",
            "\t\tif((to=a[i].to)!=fa)dfs2(to,x);",
            "}",
            "inline void Stirling(Re N){",
            "\tfor(Re i=0;i<=N;++i)S[i][i]=1;",
            "\tfor(Re i=1;i<=N;++i)",
            "\t\tfor(Re j=1;j<i;++j)",
            "\t\t\tS[j][i]=(S[j-1][i-1]+j*S[j][i-1]%P)%P;",
            "}",
            "int main(){",
            "//\tfreopen(\"123.txt\",\"r\",stdin);",
            "\tin(n),in(K),m=n-1;",
            "\twhile(m--)in(x),in(y),add(x,y),add(y,x);",
            "\tdfs1(1,0),dfs2(1,0),Stirling(K),jc[0]=1;",
            "\tfor(Re i=1;i<=K;++i)jc[i]=jc[i-1]*i%P;",
            "\tfor(Re i=1;i<=n;++i){",
            "\t\tRe ans=0;",
            "\t\tfor(Re j=0;j<=K;++j)",
            "\t\t\t(ans+=S[j][K]*jc[j]%P*(f[i][j]+g[i][j])%P)%=P;",
            "\t\tprintf(\"%d\\n\",ans);",
            "\t}",
            "}",
            ""
        ],
        "description": "插入 Crash的文明世界"
    }
}