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 146 147 148 149 150
| #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; } 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=100005; const int M=1<<18; typedef vector<ll> Poly; namespace P{ int R[M]; ll W[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) { ll w; for(int i=0;i<n;i++) { R[i]=(R[i>>1]>>1)|((i&1)*(n>>1)); if(i<R[i]) swap(a[i],a[R[i]]); } 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 opt) {ntt(&A[0],n,opt);} inline Poly operator*(Poly A,Poly B) { int n=A.size(),m=B.size(),k=n+m-1,len=1; for(;len<=k;len<<=1); A.resize(len); B.resize(len); ntt(A,len,1); ntt(B,len,1); fo(i,0,len-1) A[i]=1ll*A[i]*B[i]%mod; ntt(A,len,-1); A.resize(k); return A; } inline Poly operator+(const Poly &A,const Poly &B) { Poly C=A; C.resize(max(A.size(),B.size())); fo(i,0,B.size()-1) C[i]=Add(C[i],B[i]); return C; } } using namespace P; int n; namespace Tree{ int son[N],siz[N],oth[N]; vector<int> adj[N]; inline void add(int x,int y) { adj[x].pb(y); adj[y].pb(x); } void dfs1(int u,int pre) { siz[u]=1; for(auto v:adj[u]) if(v!=pre) { dfs1(v,u); oth[u]^=v; siz[u]+=siz[v]; if(siz[son[u]]<siz[v]) son[u]=v; } oth[u]^=son[u]; } Poly p[N],w[N]; inline void solve(int l,int r,Poly &f,Poly &g) { if(l==r){f=g=w[l]; return;} int mid=l+r>>1; Poly lf,lg,rf,rg; solve(l,mid,lf,lg); solve(mid+1,r,rf,rg); g=lg*rg; f=rf*lg+lf; } Poly dfs2(int u) { int m=0; for(int v=u;v;v=son[v]) { p[v].clear(); if(oth[v]) p[v]=dfs2(oth[v]); if(p[v].empty()) p[v].pb(0); p[v][0]++; p[v].insert(p[v].begin(),0); w[++m].swap(p[v]); } Poly f,g; solve(1,m,f,g); return f; } Poly f; inline ll work(ll x) { dfs1(1,0); f=dfs2(1); ll ans=0,now=1; fo(i,1,n) { ans=Add(ans,Mul(now,f[i])); now=Mul(now,Mul(Add(x,i),Pow(i,mod-2))); } return ans; } } int main() { PolyInit(); n=read(); ll x; scanf("%lld",&x); x%=mod; fo(i,2,n) Tree::add(read(),read()); printf("%lld",Tree::work(x)); return 0; }
|