Description D e s c r i p t i o n
一个带标号的图的价值定义为每个点度数的
p
p
次方的和。
给定和
p
p
,请计算所有个点的带标号的简单无向图的价值之和。
Solution S o l u t i o n
推式子:
ansxpansS(p,k)=======n2(n−12)∑d=0n−1dp(n−1d)∑k=0pS(p,k)xk↓∑k=0pS(p,k)(xk)k!n2(n−12)∑k=0pS(p,k)k!∑d=0n−1(n−1d)(dk)n2(n−12)∑k=0pS(p,k)k!(n−1k)2n−k−11p!∑k=0p(−1)p−kkp(pk)∑k=0p(−1)p−k(p−k)!kpk!(29)(30)(31)(32)(33)(34)(35)
(29)
a
n
s
=
n
2
(
n
−
1
2
)
∑
d
=
0
n
−
1
d
p
(
n
−
1
d
)
(30)
x
p
=
∑
k
=
0
p
S
(
p
,
k
)
x
k
↓
(31)
=
∑
k
=
0
p
S
(
p
,
k
)
(
x
k
)
k
!
(32)
a
n
s
=
n
2
(
n
−
1
2
)
∑
k
=
0
p
S
(
p
,
k
)
k
!
∑
d
=
0
n
−
1
(
n
−
1
d
)
(
d
k
)
(33)
=
n
2
(
n
−
1
2
)
∑
k
=
0
p
S
(
p
,
k
)
k
!
(
n
−
1
k
)
2
n
−
k
−
1
(34)
S
(
p
,
k
)
=
1
p
!
∑
k
=
0
p
(
−
1
)
p
−
k
k
p
(
p
k
)
(35)
=
∑
k
=
0
p
(
−
1
)
p
−
k
(
p
−
k
)
!
k
p
k
!
NTT就好了。
#include <bits/stdc++.h>
using namespace std;
const int G = 3;
const int N = 808080;
const int MOD = 998244353;
typedef long long ll;
inline char get(void) {
static char buf[100000], *S = buf, *T = buf;
if (S == T) {
T = (S = buf) + fread(buf, 1, 100000, stdin);
if (S == T) return EOF;
}
return *S++;
}
template<typename T>
inline void read(T &x) {
static char c; x = 0; int sgn = 0;
for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
if (sgn) x = -x;
}
int g, ig, num, L;
int n, p, m, ans;
int w[2][N];
int R[N];
int inv[N], fac[N], ifac[N];
int Sp[N], A[N], B[N], C[N];
inline int Pow(int a, int b) {
int c = 1;
while (b) {
if (b & 1) c = (ll)c * a % MOD;
b >>= 1; a = (ll)a * a % MOD;
}
return c;
}
inline int Inv(int x) {
return Pow(x, MOD - 2);
}
void Prep(int n) {
g = Pow(G, (MOD - 1) / n);
ig = Inv(g); num = n;
w[0][0] = w[1][0] = 1;
for (int i = 1; i <= n; i++) {
w[0][i] = (ll)w[0][i - 1] * ig % MOD;
w[1][i] = (ll)w[1][i - 1] * g % MOD;
}
}
inline void FFT(int *a, int n, int r) {
static int x, y, INV;
for (int i = 0; i < n; i++)
if (R[i] > 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++) {
x = a[j + k];
y = (ll)a[j + k + i] * w[r][num / (i << 1) * k] % MOD;
a[j + k] = (x + y) % MOD;
a[j + k + i] = (x - y + MOD) % MOD;
}
if (!r) {
INV = Inv(n);
for (int i = 0; i < n; i++)
a[i] = (ll)a[i] * INV % MOD;
}
}
inline void Add(int &x, int a) {
x = (x + a) % MOD;
}
int main(void) {
freopen("1.in", "r", stdin);
read(n); read(p);
for (m = 1; m <= p; m <<= 1) ++L;
m <<= 1; Prep(m);
for (int i = 1; i < m; i++)
R[i] = (R[i >> 1] >> 1) | ((i & 1) << L);
inv[1] = 1;
for (int i = 2; i < m; i++)
inv[i] = (ll)(MOD - MOD / i) * inv[MOD % i] % MOD;
ifac[0] = fac[0] = 1;
for (int i = 1; i < m; i++) {
ifac[i] = (ll)ifac[i - 1] * inv[i] % MOD;
fac[i] = (ll)fac[i - 1] * i % MOD;
}
for (int i = 0; i <= p; i++) {
A[i] = (ll)Pow(i, p) * ifac[i] % MOD;
if (i & 1) B[i] = MOD - ifac[i];
else B[i] = ifac[i];
}
C[0] = 1;
for (int i = 1; i <= p; i++)
C[i] = (ll)C[i - 1] * (n - i) % MOD * inv[i] % MOD;
FFT(A, m, 1); FFT(B, m, 1);
for (int i = 0; i < m; i++) Sp[i] = (ll)A[i] * B[i] % MOD;
FFT(Sp, m, 0);
for (int i = 0; i <= p; i++)
Add(ans, (ll)Sp[i] * fac[i] % MOD * C[i] % MOD * Pow(2, n - i - 1) % MOD);
ans = (ll)ans * n % MOD * Pow(2, (ll)(n - 1) * (n - 2) / 2 % (MOD - 1)) % MOD;
cout << ans << endl;
return 0;
}