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
| #include<bits/stdc++.h> using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef double db; typedef pair <int,int> Pii; #define reg register #define mp make_pair #define pb push_back #define Mod1(x) ((x>=P)&&(x-=P)) #define Mod2(x) ((x<0)&&(x+=P)) #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i) template <class T> inline void cmin(T &a,T b){ ((a>b)&&(a=b)); } template <class T> inline void cmax(T &a,T b){ ((a<b)&&(a=b)); }
char IO; template <class T=int> T rd(){ T s=0; int f=0; while(!isdigit(IO=getchar())) f|=IO=='-'; do s=(s<<1)+(s<<3)+(IO^'0'); while(isdigit(IO=getchar())); return f?-s:s; }
const int N=310,P=998244353; ll qpow(ll x,ll k=P-2){ ll res=1; for(;k;k>>=1,x=x*x%P) if(k&1) res=res*x%P; return res; }
int n,d,m; vector <int> G[N]; int dp[N][N*2],g[N*2],D[N]; vector <int> tmp; void dfs(int u,int f) { rep(i,0,m) dp[u][i]=0; dp[u][n+d+2]=1,dp[u][n]=1; for(int v:G[u]) if(v!=f) { dfs(v,u); cmax(D[u],D[v]+1); rep(i,0,m) g[i]=dp[u][i],dp[u][i]=0; tmp.clear(); rep(i,0,m) if(dp[v][i]) tmp.pb(i); rep(i,0,m) if(g[i]) { for(int j:tmp) { if(max(j-n-2,i-n-2)>=max(n-i,n-j)) dp[u][max(i,j)]=(dp[u][max(i,j)]+1ll*g[i]*dp[v][j])%P; else dp[u][min(i,j)]=(dp[u][min(i,j)]+1ll*g[i]*dp[v][j])%P; } } } rep(i,0,m) g[i]=dp[u][i],dp[u][i]=0; rep(i,1,n) dp[u][i-1]=g[i]; rep(i,n+2,m) dp[u][i-1]=g[i]; dp[u][n+1]+=g[n+1],Mod1(dp[u][n+1]); }
int main(){ n=rd(),m=n*2+2; rep(i,2,n) { int u=rd(),v=rd(); G[u].pb(v),G[v].pb(u); } int all=qpow(2,n),ans=0; for(d=1;d<n;++d) { dfs(1,0); int s=all; rep(i,n+1,m) s-=dp[1][i],Mod2(s); ans=(ans+s)%P; } ans=ans*qpow(all)%P; printf("%d\n",ans); }
|