#include using namespace std; #define modulo 1000000007 #define mod(mod_x) ((((long long)mod_x+modulo))%modulo) #define Inf 1000000000000000010 int Ans = 0; struct node{ vector dp; node(int k){ dp.resize(k,1); } node(){ } }; template struct rerooting{ F0 func0; F1 func1; T init_value; vector v; vector ans; vector visited; rerooting(vector> &E,F0 f0,F1 f1,T iv):func0(f0),func1(f1){ init_value = iv; v.resize(E.size()); ans.resize(E.size()); visited.resize(E.size(),false); for(int i=0;i> &E,int now,int p){ v[now] = init_value; for(int i=0;i> &E,int now,int p,T pv){ for(int i=pv.dp.size()-1;i>=0;i--){ if(i==0)pv.dp[i]=0; else{ pv.dp[i] = pv.dp[i-1]; } } vector S(E[now].size(),init_value); if(S.size()>1){ for(int i=S.size()-2;i>=0;i--){ int to = E[now][i+1]; T x = v[to]; if(to==p)x = pv; S[i] = func0(x,S[i+1]); } } T temp = init_value; for(int i=0;i>N>>K; vector> E(N,vector()); for(int i=0;i>u>>v; u--;v--; E[u].push_back(v); E[v].push_back(u); } auto f0 = [](node a,node b){ node ret = a; for(int i=0;i rr(E,f0,f1,t); cout<