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
| #include "iostream" #include "algorithm" #include "cstring" #include "cstdio" #include "cmath" #include "vector" #include "map" #include "set" #include "queue" using namespace std; #define MAXN 1000006
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all(x) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) #define P 998244353 typedef long long ll; int n , A[MAXN]; vi G[MAXN];
int Pow( int x , int a ) { int ret = 1; while( a ) { if( a & 1 ) ret = 1ll * ret * x % P; x = 1ll * x * x % P , a >>= 1; } return ret; }
int hea[MAXN] , mxd[MAXN]; void dfs( int u , int fa ) { mxd[u] = 1; for( int& v : G[u] ) if( v != fa ) { dfs( v , u ); if( !hea[u] || mxd[v] > mxd[hea[u]] ) hea[u] = v , mxd[u] = mxd[v] + 1; } }
int dp[MAXN * 2] , tg[MAXN * 2] , po[MAXN * 2] , tl[MAXN * 2] , cnt; inline void pd( int x ) { if( tg[x] != 1 ) { if( !tl[x] ) { dp[x + 1] = 1ll * dp[x + 1] * tg[x] % P; tg[x + 1] = 1ll * tg[x + 1] * tg[x] % P; } tg[x] = 1; } } inline void mul( int x , int c ) { dp[x] = 1ll * dp[x] * c % P , tg[x] = 1ll * tg[x] * c % P; } void wkr( int u , int fa ) { po[u] = ++ cnt , dp[cnt] = 1; if( hea[u] ) wkr( hea[u] , u ); else tl[po[u]] = 1; int S , s , t; for( int v : G[u] ) if( v != fa && v != hea[u] ) { wkr( v , u ); S = dp[po[u]] , s = 0; pd( po[u] ); rep( i , 0 , mxd[v] - 1 ) { pd( po[u] + i + 1 ) , pd( po[v] + i ); s = ( s + dp[po[v] + i] ) % P; t = dp[po[u] + i + 1]; dp[po[u] + i + 1] = ( ( t + 1ll * S * dp[po[v] + i] % P ) % P + 1ll * s * t % P ) % P; S = ( S + t ) % P; } mul( po[u] + mxd[v] + 1 , s + 1 ); } }
int S[MAXN] , ttg[MAXN]; int Just_DOIT( ) { fill( ttg , ttg + MAXN - 1 , 1 ); fill( tg , tg + MAXN * 2 - 1 , 1 ); fill( S , S + MAXN - 1 , 1 ); po[1] = ++ cnt; if( hea[1] ) wkr( hea[1] , 1 ); for( int v : G[1] ) { if( v != hea[1] ) wkr( v , 1 ); int s = 0; rep( i , 0 , mxd[v] - 1 ) { pd( po[v] + i ); s = ( s + dp[po[v] + i] ) % P; S[i + 1] = 1ll * S[i + 1] * ( 1 + s ) % P; } ttg[mxd[v] + 1] = 1ll * ttg[mxd[v] + 1] * ( s + 1 ) % P; } rep( i , 0 , mxd[1] ) S[i] = 1ll * S[i] * ttg[i] % P , ttg[i + 1] = 1ll * ttg[i] * ttg[i + 1] % P; int re = 0 , s = 0; for( int v : G[1] ) { s = 0; rep( i , 0 , mxd[v] - 1 ) { re = ( re + 1ll * S[i] * Pow( s + 1 , P - 2 ) % P * dp[po[v] + i] % P ) % P; s = ( s + dp[po[v] + i] ) % P; } } return re; }
void solve() { cin >> n; int u , v; rep( i , 2 , n ) { scanf("%d%d",&u,&v) , G[u].pb( v ) , G[v].pb( u ); } dfs( 1 , 1 ); cout << Just_DOIT( ) << endl; }
signed main() {
solve(); }
|