[Luogu5827] 点双连通图计数

刚开始以为和边双没啥差别..结果后来搞了好久。

UPD:好像存在更简单的方法。

做法

\(n\) 个点的点双连通图有 \(f_n\) 个,连通图有 \(g_n\) 个,它们的 EGF 分别是 \(F(x)\)\(G(x)\)。(均不钦定根)

我们认为一个点的图不点双连通,且这一个点为割点。由于题目里一个点是算点双连通图的,要特判下。

\(n\) 个点的根不是割点的有根连通图个数为 \(b_n\),其 EGF 为 \(B(x)\)。根据割点的定义,去掉根之后的点构成一个连通图,所以 \(b_n = \frac n {n!}(2^{n-1}-1)(n-1)!g_{n-1}=(2^{n-1}-1)g_{n-1}\ (n \ge 2)\)

另一方面,包含不是割点的点的点双是唯一的,我们可以枚举包含根的点双的大小来计算 \(B(x)\)。设 \(H(x) = G'(x)\) (对 EGF 求导相当于平移了),包含根的点双大小为 \(n\) 且根不是割点的有根连通图的 EGF 为 \(n\frac{f_n}{n!}x^n H^{n-1}(x)\) (考虑决定根,然后决定这个点双中除了根以外每个点挂的连通图)。

\(C(x) = \frac{B(x)}x\),则

\[ B(x) = \sum_{n \ge 1} n\frac{f_n}{n!} x^n H^{n-1}(x) = xF'(xH(x)) \\\\ xC(x) = xF'(xH(x)) \\\\ C(x) = F'(xH(x)) \]

作 (扩展) 拉格朗日反演可得

\[ [x^n] F(x) = \frac 1 n[x^{n-1}] F'(x)=\frac 1 {n(n-1)}[x^{-1}]\frac{C'(x)}{(xH(x))^{n-1}} \]

代码

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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

const int maxn = 100010;
const int mod = 998244353;
const int g = 3;

int wa[8*maxn], wb[8*maxn], wc[8*maxn], rev[8*maxn];

inline int mo(int x) {
if (x >= mod) return x - mod;
return x;
}

int qpow(int x, int y) {
int ret = 1;
while (y) {
if (y & 1) ret = 1LL*ret*x%mod;
x = 1LL*x*x%mod;
y >>= 1;
}
return ret;
}

int qpowl(int x, long long y) {
int ret = 1;
while (y) {
if (y & 1) ret = 1LL*ret*x%mod;
x = 1LL*x*x%mod;
y >>= 1;
}
return ret;
}

struct poly {
int *a, len;
poly(int l_ = 0) {
len = l_;
a = new int[l_];
for (int i = 0; i < l_; i++) a[i] = 0;
}
};

void ntt(int *a, int l, int ty) {
rev[0] = 0;
for (int i = 1; i < (1<<l); i++) rev[i] = ((rev[i >> 1] >> 1) | ((i&1) << (l-1)));
for (int i = 0; i < (1<<l); i++) if (rev[i] > i) swap(a[i], a[rev[i]]);
for (int len = 2; len <= (1<<l); len <<= 1) {
int wn = qpow(g, (mod-1)/len);
for (int i = 0; i < (1<<l); i += len) {
int w = 1;
for (int j = 0; j < (len>>1); j++) {
int v1 = a[i+j], v2 = 1LL*w*a[i+j+(len>>1)]%mod;
a[i+j] = mo(v1 + v2);
a[i+j+(len >> 1)] = mo(v1 + mod - v2);
w = 1LL*w*wn%mod;
}
}
}
if (ty == -1) {
int inv = qpow(1<<l, mod-2);
for (int i = 0; i < (1<<l); i++) a[i] = 1LL*a[i]*inv%mod;
for (int i = 1; i < (1<<(l-1)); i++) swap(a[i], a[(1<<l)-i]);
}
}

poly operator*(const poly &p1, const poly &p2) {
poly ret(p1.len + p2.len - 1);
int l = 0; while ((1<<l) < ret.len) ++ l;
for (int i = 0; i < (1<<l); i++) wa[i] = wb[i] = 0;
for (int i = 0; i < p1.len; i++) wa[i] = p1.a[i];
for (int i = 0; i < p2.len; i++) wb[i] = p2.a[i];
ntt(wa, l, 1); ntt(wb, l, 1);
for (int i = 0; i < (1<<l); i++) wc[i] = 1LL*wa[i]*wb[i]%mod;
ntt(wc, l, -1);
for (int i = 0; i < ret.len; i++) ret.a[i] = wc[i];
return ret;
}

poly polyInv(const poly &p) {
if (p.len == 1) {
poly ret(1);
ret.a[0] = qpow(p.a[0], mod-2);
return ret;
}
int nlen = (p.len+1)/2;
poly tmp(nlen); for (int i = 0; i < nlen; i++) tmp.a[i] = p.a[i];
poly G = polyInv(tmp);
poly ret(p.len);
for (int i = 0; i < G.len; i++) ret.a[i] = 1LL*2*G.a[i]%mod;
poly t = p*G*G;
for (int i = 0; i < p.len; i++) ret.a[i] = (ret.a[i] + mod - t.a[i]) % mod;
return ret;
}

poly polyLn(const poly &p) {
if (p.len == 1) return poly(1);
poly inv = polyInv(p);
poly d(p.len);
for (int i = 0; i+1 < p.len; i++) {
d.a[i] = 1LL*p.a[i+1]*(i+1)%mod;
}
inv = inv * d;
poly ret(p.len);
for (int i = 1; i < ret.len; i++) {
ret.a[i] = 1LL*qpow(i, mod-2)*inv.a[i-1]%mod;
}
return ret;
}

poly polyExp(const poly &p) {
if (p.len == 1) {
poly ret(1);
ret.a[0] = 1;
return ret;
}
int nlen = (p.len+1)/2;
poly tmp(nlen); for (int i = 0; i < nlen; i++) tmp.a[i] = p.a[i];
poly G = polyExp(tmp);
poly t(p.len), v(p.len);
for (int i = 0; i < nlen; i++) v.a[i] = G.a[i];
v = polyLn(v);
for (int i = 0; i < p.len; i++) {
t.a[i] = (mod - v.a[i] + p.a[i]) % mod;
}
t.a[0] = (t.a[0] + 1) % mod;
t = t*G;
poly ret(p.len);
for (int i = 0; i < ret.len; i++) ret.a[i] = t.a[i];
return ret;
}

void polyDiv(const poly &F, const poly &Q, poly &P, poly &R) {
poly rF(F.len-Q.len+1), rQ(F.len-Q.len+1);
for (int i = 0; i < rF.len; i++) rF.a[i] = F.a[F.len-1-i];
for (int i = 0; i < rQ.len; i++) if (Q.len-1-i >= 0) rQ.a[i] = Q.a[Q.len-1-i];
poly v = rF*polyInv(rQ);
for (int i = 0; i < P.len; i++) P.a[i] = v.a[F.len-Q.len-i];
poly t = P*Q;
for (int i = 0; i < R.len; i++) R.a[i] = (F.a[i] + mod - t.a[i]) % mod;
}

poly polySqrt(const poly &p) {
if (p.len == 1) {
poly ret(1);
ret.a[0] = 1;
return ret;
}
int nlen = (p.len+1)/2;
poly np(nlen); for (int i = 0; i < nlen; i++) np.a[i] = p.a[i];
poly F0 = polySqrt(np);
poly exF0(p.len);
for (int i = 0; i < F0.len; i++) exF0.a[i] = F0.a[i];
poly tmp = F0*F0;
poly extmp(p.len);
for (int i = 0; i < p.len; i++) {
if (i < tmp.len) extmp.a[i] = tmp.a[i];
extmp.a[i] = (extmp.a[i] + mod - p.a[i]) % mod;
}
poly Q(p.len); for (int i = 0; i < p.len; i++) Q.a[i] = 1LL*exF0.a[i]*2%mod;
poly tt = extmp*polyInv(Q);
poly res(p.len);
for (int i = 0; i < res.len; i++) {
res.a[i] = (exF0.a[i] + mod - tt.a[i]) % mod;
}
return res;
}

int fac[maxn], ifac[maxn];

int main() {
int T = 5;
fac[0] = ifac[0] = 1;
for (int i = 1; i <= 100000; i++) {
fac[i] = 1LL * fac[i-1] * i % mod;
ifac[i] = 1LL * ifac[i-1] * qpow(i, mod-2) % mod;
}
const int N = 100000;
poly tmp(N + 1);
for (int i = 0; i <= N; i++) {
tmp.a[i] = 1LL * qpowl(2, 1LL * i * (i - 1) / 2) * ifac[i] % mod;
}
poly lnT = polyLn(tmp);
poly G(N + 1);
for (int i = 1; i <= N; i++) {
// G.a[i] = 1LL * lnT.a[i] * i % mod;
G.a[i] = lnT.a[i];
}
poly H(N);
for (int i = 0; i < N; i++) {
H.a[i] = 1LL * (i + 1) * G.a[i+1] % mod;
}
poly B(N+1); int _ = 1;
for (int i = 1; i <= N; i++) {
B.a[i] = 1LL * (_ - 1) * G.a[i-1] % mod;
_ = 1LL * _ * 2 % mod;
}
poly C(N);
for (int i = 0; i < N; i++) {
C.a[i] = B.a[i+1];
}
poly lnH = polyLn(H);
poly dC(N-1);
for (int i = 0; i < N-1; i++) {
dC.a[i] = 1LL * C.a[i+1] * (i+1) % mod;
}
while (T --) {
int n;
scanf("%d", &n);
if (n == 1) {
puts("1");
continue;
}
poly nH = poly(n);
for (int i = 0; i < n; i++) {
nH.a[i] = 1LL * lnH.a[i] * (mod - (n - 1)) % mod;
}
poly res = polyExp(nH) * dC;
int ans = 1LL * res.a[n - 2] * qpow(n - 1, mod-2) % mod * fac[n - 1] % mod;
printf("%d\n", ans);
}
return 0;
}