(mathcal{Description})
link.
求有 (n) 个结点的点双连通图的个数,对 (998244353) 取模。
(nle10^5)。
(mathcal{Solution})
奇怪的 GF 增加了 w!
对于带标号简单无向图,其 ( ext{EGF}) 为 (F(x)=displaystylesum_{i=0}^{+infty}frac{2^{ichoose2}x^i}{i!})(任意两点间有连与不连两种情况。)在此基础上,我们要求图连通(注意这里不是点双连通),即对于带标号简单连通无向图,( ext{EGF}) 有 (G(x)=ln F(x))。
以下规定所有的图都是带标号的简单无向图。设有根连通图的 ( ext{EGF}) 为 (D(x)),显然 (D(x)=nG(x))。并设 (i) 个结点的点双连通图个数为 (b_i)。考虑任意一个简单无向图的根,它可能被包含在多个点双中。首先特判掉 (n=1) ——单点的情况。现在对于每一个不是根且在点双连通分量上的点,我们都可以在上面插上一个以其为根的无向连通图,并且不会影响到包含原来的根的任何点双连通分量的大小。所以每一个点双块的 ( ext{EGF}) 是:
令 (B(x)=sum_{i=0}^{+infty}b_{i+1}frac{x^i}{i!}),我们反过来表示 (D(x)),则:
开始推式子,先对上式变形:
令 (D^{-1}) 是 (D) 的复合逆,代入得:
令 (H(x)=lnfrac{D(x)}x),那么有 (B(x)=Hleft(D^{-1}(x) ight))。利用扩展拉格朗日反演,有:
把后面的多项式幂变形,并交换分子分母以便运算,得:
(D) 易求,那么整个式子都能用亿堆多项式模板算出来。复杂度 (mathcal O(nlog n))。
(mathcal{Code})
#include <cmath>
#include <cstdio>
const int MAXN = 1 << 18, MOD = 998244353;
int n, fac[MAXN + 5], ifac[MAXN + 5], inv[MAXN + 5], F[MAXN + 5], G[MAXN + 5];
int H[MAXN + 5], lH[MAXN + 5], dH[MAXN + 5];
inline int qkpow ( int a, int b, const int p = MOD ) {
int ret = 1;
for ( ; b; a = 1ll * a * a % p, b >>= 1 ) ret = 1ll * ret * ( b & 1 ? a : 1 ) % p;
return ret;
}
namespace Poly {
const int G = 3;
inline void NTT ( const int n, int* A, const int tp ) {
static int lstn = -1, rev[MAXN + 5] {};
if ( lstn ^ n ) {
int lgn = log ( n ) / log ( 2 ) + 0.5;
for ( int i = 0; i < n; ++ i ) rev[i] = ( rev[i >> 1] >> 1 ) | ( ( i & 1 ) << lgn >> 1 );
lstn = n;
}
for ( int i = 0; i < n; ++ i ) if ( i < rev[i] ) A[i] ^= A[rev[i]] ^= A[i] ^= A[rev[i]];
for ( int i = 2, stp = 1; i <= n; i <<= 1, stp <<= 1 ) {
int w = qkpow ( G, ( MOD - 1 ) / i );
if ( ! ~ tp ) w = qkpow ( w, MOD - 2 );
for ( int j = 0; j < n; j += i ) {
for ( int k = j, r = 1; k < j + stp; ++ k, r = 1ll * r * w % MOD ) {
int ev = A[k], ov = 1ll * r * A[k + stp] % MOD;
A[k] = ( ev + ov ) % MOD, A[k + stp] = ( ev - ov + MOD ) % MOD;
}
}
}
if ( ! ~ tp ) for ( int i = 0; i < n; ++ i ) A[i] = 1ll * A[i] * inv[n] % MOD;
}
inline void polyDir ( const int n, const int* A, int* R ) {
for ( int i = 1; i < n; ++ i ) R[i - 1] = 1ll * i * A[i] % MOD;
R[n - 1] = 0;
}
inline void polyInt ( const int n, const int* A, int* R ) {
for ( int i = n - 1; ~ i; -- i ) R[i + 1] = 1ll * inv[i + 1] * A[i] % MOD;
R[0] = 0;
}
inline void polyInv ( const int n, const int* A, int* R ) {
static int tmp[2][MAXN + 5] {};
if ( n == 1 ) return void ( R[0] = qkpow ( A[0], MOD - 2 ) );
polyInv ( n >> 1, A, R );
for ( int i = 0; i < n; ++ i ) tmp[0][i] = A[i], tmp[1][i] = R[i];
NTT ( n << 1, tmp[0], 1 ), NTT ( n << 1, tmp[1], 1 );
for ( int i = 0; i < n << 1; ++ i ) tmp[0][i] = 1ll * tmp[0][i] * tmp[1][i] % MOD * tmp[1][i] % MOD;
NTT ( n << 1, tmp[0], -1 );
for ( int i = 0; i < n; ++ i ) R[i] = ( 2ll * R[i] % MOD - tmp[0][i] + MOD ) % MOD;
for ( int i = 0; i < n << 1; ++ i ) tmp[0][i] = tmp[1][i] = 0;
}
inline void polyLn ( const int n, const int* A, int* R ) {
static int tmp[2][MAXN + 5] {};
polyDir ( n, A, tmp[0] ), polyInv ( n, A, tmp[1] );
NTT ( n << 1, tmp[0], 1 ), NTT ( n << 1, tmp[1], 1 );
for ( int i = 0; i < n << 1; ++ i ) tmp[0][i] = 1ll * tmp[0][i] * tmp[1][i] % MOD;
NTT ( n << 1, tmp[0], -1 ), polyInt ( n << 1, tmp[0], R );
for ( int i = 0; i < n << 1; ++ i ) tmp[0][i] = tmp[1][i] = 0;
}
inline void polyExp ( const int n, const int* A, int* R ) {
static int tmp[MAXN + 5] {};
if ( n == 1 ) return void ( R[0] = 1 );
polyExp ( n >> 1, A, R ), polyLn ( n, R, tmp );
tmp[0] = ( A[0] + 1 - tmp[0] + MOD ) % MOD;
for ( int i = 1; i < n; ++ i ) tmp[i] = ( A[i] - tmp[i] + MOD ) % MOD;
NTT ( n << 1, tmp, 1 ), NTT ( n << 1, R, 1 );
for ( int i = 0; i < n << 1; ++ i ) R[i] = 1ll * R[i] * tmp[i] % MOD;
NTT ( n << 1, R, -1 );
for ( int i = n; i < n << 1; ++ i ) R[i] = tmp[i] = 0;
}
} // namespace Poly.
inline void init () {
inv[1] = fac[0] = ifac[0] = fac[1] = ifac[1] = 1;
for ( int i = 2; i <= MAXN; ++ i ) {
fac[i] = 1ll * i * fac[i - 1] % MOD;
inv[i] = 1ll * ( MOD - MOD / i ) * inv[MOD % i] % MOD;
ifac[i] = 1ll * inv[i] * ifac[i - 1] % MOD;
}
int len = MAXN >> 1;
for ( int i = 0; i < len; ++ i ) F[i] = 1ll * qkpow ( 2, ( i * ( i - 1ll ) >> 1 ) % ( MOD - 1 ) ) * ifac[i] % MOD;
Poly::polyLn ( len, F, G );
for ( int i = 0; i < len; ++ i ) G[i] = 1ll * i * G[i] % MOD;
for ( int i = 0; i < len - 1; ++ i ) G[i] = G[i + 1];
G[len - 1] = 0;
Poly::polyLn ( len, G, H ), Poly::polyDir ( len, H, dH );
Poly::NTT ( MAXN, dH, 1 );
}
inline void solve () {
int len = MAXN >> 1;
if ( ! -- n ) return void ( puts ( "1" ) );
for ( int i = 0; i < MAXN; ++ i ) F[i] = G[i] = 0;
for ( int i = 0; i < len; ++ i ) F[i] = 1ll * ( MOD - n ) % MOD * H[i] % MOD;
Poly::polyExp ( len, F, G ), Poly::NTT ( MAXN, G, 1 );
for ( int i = 0; i < MAXN; ++ i ) G[i] = 1ll * dH[i] * G[i] % MOD;
Poly::NTT ( MAXN, G, -1 );
printf ( "%d
", int ( 1ll * inv[n] * fac[n] % MOD * G[n - 1] % MOD ) );
}
int main () {
init ();
for ( int i = 1; i <= 5; ++ i ) scanf ( "%d", &n ), solve ();
return 0;
}