1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| #include <bits/stdc++.h> using namespace std; #define FO(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout) #define fo(i,j,k) for(int i=(j),end_i=(k);i<=end_i;i++) #define fd(i,j,k) for(int i=(j),end_i=(k);i>=end_i;i--) #define DEBUG(x) cerr<<#x<<"="<<x<<endl #define all(x) (x).begin(),(x).end() #define cle(x) memset(x,0,sizeof(x)) #define lowbit(x) ((x)&-(x)) #define ll long long #define ull unsigned ll #define db double #define lb long db #define pb push_back #define mp make_pair #define fi first #define se second inline int read() { int x=0; char ch=getchar(); bool f=0; for(;ch<'0'||ch>'9';ch=getchar()) if(ch=='-') f=1; for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+(ch^48); return f?-x:x; } #define CASET fo(___,1,read()) const ll mod=998244353; inline ll Add(ll x,ll y){x+=y; return (x<mod)?x:x-mod;} inline ll Dec(ll x,ll y){x-=y; return (x<0)?x+mod:x;} inline ll Mul(ll x,ll y){return x*y%mod;} inline ll Pow(ll x,ll y){y%=(mod-1);ll ans=1;for(;y;y>>=1,x=x*x%mod)if(y&1) ans=ans*x%mod;return ans;} const int N=1e5+5; const int M=1<<18;
typedef vector<ll> Poly; ll W[M]; int R[M]; inline void PolyInit() { ll wn; for(int i=1;i<M;i<<=1) { W[i]=1; wn=Pow(3,(mod-1)/2/i); fo(j,1,i-1) W[i+j]=W[i+j-1]*wn%mod; } } inline void ntt(ll *a,int n,int opt) { fo(i,0,n-1) { R[i]=(R[i>>1]>>1)|((i&1)*(n>>1)); if(i<R[i]) swap(a[i],a[R[i]]); } ll w; for(int i=1;i<n;i<<=1) for(int j=0;j<n;j+=(i<<1)) for(int k=0;k<i;k++) w=W[i+k]*a[i+j+k]%mod, a[i+j+k]=Dec(a[j+k],w), a[j+k]=Add(a[j+k],w); if(opt==1) return; reverse(a+1,a+n); w=Pow(n,mod-2); fo(i,0,n-1) a[i]=w*a[i]%mod; } inline void ntt(Poly &A,int n,int t){ntt(&A[0],n,t);} ll fac[N],inv[N]; inline void init(int n) { fac[0]=1; fo(i,1,n) fac[i]=fac[i-1]*i%mod; inv[n]=Pow(fac[n],mod-2); fd(i,n,1) inv[i-1]=inv[i]*i%mod; } int n,k; namespace Tree{ ll s1,s2,s,h[N],sh[N]; int siz[N]; vector<int> adj[N]; inline void add(int x,int y) { adj[x].pb(y); adj[y].pb(x); } vector<int> w; int now; void solve(int l,int r,Poly &f,Poly &g) { if(l==r) { f.clear(); f.pb(1); f.pb(siz[w[l]]); ll sum=Add(sh[w[l]],h[w[l]]); g.clear(); g.pb(sum); g.pb(Mul(sum,now)); return; } int mid=l+r>>1; Poly lf,lg,rf,rg; solve(l,mid,lf,lg); solve(mid+1,r,rf,rg); int len=1,m=lf.size()+rf.size()-1; for(;len<m;len<<=1); lf.resize(len); ntt(lf,len,1); lg.resize(len); ntt(lg,len,1); rf.resize(len); ntt(rf,len,1); rg.resize(len); ntt(rg,len,1); f.resize(len); g.resize(len); fo(i,0,len-1) f[i]=lf[i]*rf[i]%mod, g[i]=Add(Mul(lf[i],rg[i]),Mul(lg[i],rf[i])); ntt(f,len,-1); ntt(g,len,-1); f.resize(m); g.resize(m); } void dfs(int u,int pre) { siz[u]=1; for(auto v:adj[u]) if(v!=pre) dfs(v,u); w.clear(); for(auto v:adj[u]) if(v!=pre) { siz[u]+=siz[v]; w.pb(v); sh[u]=Add(sh[u],Add(h[v],sh[v])); } now=n-siz[u]; if(!w.size()) w.pb(0); Poly f,g; solve(0,w.size()-1,f,g); fo(i,0,min(k,(int)f.size()-1)) h[u]=Add(h[u],Mul(fac[k]*inv[k-i]%mod,f[i])); fo(i,0,min(k,(int)g.size()-1)) s=Add(s,Mul(fac[k]*inv[k-i]%mod,g[i])); s1=Add(s1,h[u]); s2=Add(s2,h[u]*h[u]%mod); s=Dec(s,sh[u]*h[u]%mod); } inline ll work() { dfs(1,0); return Add(s,Mul(Pow(2,mod-2),Dec(s1*s1%mod,s2))); } } int main() { n=read(); k=read(); if(k==1) return printf("%lld",1ll*n*(n-1)/2%mod)&0; PolyInit(); init(k); fo(i,2,n) Tree::add(read(),read()); printf("%lld",Tree::work()); return 0; }
|