显然答案是总哈密顿回路数除以值得记录的竞赛图数

那么先求解总哈密顿回路数,考虑每个哈密顿回路会在几个值得记录的竞赛图中,则有
$$
Hamitons = (n - 1)!2^{C_n^2 - n}
$$
即总共有 $(n - 1)!$ 种哈密顿回路,然后剩下的边随便选

于是现在考虑值得记录的竞赛图数

首先如果一个竞赛图要有哈密顿回路,那么它至少要有一个包含所有节点的环,即该图是强连通的,并且显然非强连通竞赛图它一定不存在哈密顿回路,所以有结论

有且仅有强连通竞赛图存在哈密顿回路

那么问题转化为求解强连通竞赛图

发现正面难以求解,就考虑反面求解

设 $f_n$ 表示 $n$ 个节点的强连通竞赛图数,$g_n$ 表示 $n$ 个节点的竞赛图数(即 $2^{C_n^2}$),可得 $DP$ 方程
$$
f_n = g_n - \sum\limits_{j = 1}^{n - 1} f_jg_{n - j}\dbinom{n}{j}
$$
其中求解非强连通竞赛图部分是每次将拓扑序最小的强连通分量提取出来计数,那么剩下的点随意连接(注意,此时取的是拓扑序最小的强联通分量,故该强联通分量与其它连通分量的连边方向是固定的)

现在考虑优化
$$
\frac{f_n}{n!} = \frac{g_n}{n!} - \sum\limits_{j = 1}^{n - 1} \frac{f_j}{j!}\frac{g_{n - j}}{(n - j)!}
$$

令指数型生成函数 $F(x) = \sum\limits_n^{\infty} \frac{f_n}{n!}, G(x) = \sum\limits_n^{\infty} \frac{g_n}{n!}$,易知
$$
\begin{aligned}
F(x) &= G(x) - F(x)G(x) \\
F(x) &= \frac{G(x)}{1 + G(x)}
\end{aligned}
$$

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
#include <iostream>
#include <cstdio>
#include <cstring>

#define MOD 998244353
#define g 3

using namespace std;

typedef long long LL;

const int MAXN = 1e05 + 10;

LL power (LL x, LL p) {
LL cnt = 1;
while (p) {
if (p & 1)
cnt = cnt * x % MOD;
x = x * x % MOD;
p >>= 1;
}
return cnt;
}
const LL invg = power (g, MOD - 2);

int oppo[MAXN << 2]= {0};
void DFT (LL* a, int limit, int inv) {
for (int i = 0; i < limit; i ++)
if (i < oppo[i])
swap (a[i], a[oppo[i]]);
for (int mid = 1; mid < limit; mid <<= 1) {
LL omega = power (inv == 1 ? g : invg, 1ll * (MOD - 1) / (mid << 1));
for (int n = mid << 1, j = 0; j < limit; j += n) {
LL x = 1;
for (int k = 0; k < mid; k ++, x = x * omega % MOD) {
LL a1 = a[j + k], xa2 = x * a[j + mid + k] % MOD;
a[j + k] = (a1 + xa2) % MOD;
a[j + mid + k] = (a1 - xa2 + MOD) % MOD;
}
}
}
}
LL a1[MAXN << 2]= {0}, a2[MAXN << 2]= {0};
void NTT (LL* A, LL* B, int n, int m) {
int limit, lim;
for (limit = 1, lim = 0; limit < n + m; limit <<= 1, lim ++);
for (int i = 0; i < limit; i ++)
oppo[i] = (oppo[i >> 1] >> 1) | ((i & 1) << (lim - 1));
for (int i = 0; i < limit; i ++)
a1[i] = a2[i] = 0;
for (int i = 0; i <= n; i ++)
a1[i] = A[i];
for (int i = 0; i <= m; i ++)
a2[i] = B[i];
DFT (a1, limit, 1), DFT (a2, limit, 1);
for (int i = 0; i < limit; i ++)
a1[i] = a1[i] * a2[i] % MOD;
DFT (a1, limit, - 1);
LL invn = power (limit, MOD - 2);
for (int i = 0; i < limit; i ++)
A[i] = a1[i] * invn % MOD;
}
LL temp[MAXN << 2]= {0};
void inverse (int deg, LL* A, LL* B) {
if (deg == 1) {
B[0] = 1;
return ;
}
inverse ((deg + 1) >> 1, A, B);
int n, lim;
for (n = 1, lim = 0; n <= (deg << 1); n <<= 1, lim ++);
for (int i = 0; i < n; i ++)
oppo[i] = (oppo[i >> 1] >> 1) | ((i & 1) << (lim - 1));
for (int i = 0; i < n; i ++)
temp[i] = 0;
for (int i = 0; i < deg; i ++)
temp[i] = A[i];
NTT (temp, B, deg, deg), NTT (temp, B, deg, deg);
for (int i = 0; i < deg; i ++)
B[i] = (2ll * B[i] % MOD - temp[i] + MOD) % MOD;
}

LL fact[MAXN]= {0};

int N;
LL F[MAXN << 2]= {0};
LL G[MAXN]= {0}, invG[MAXN << 2]= {0};

LL answer[MAXN]= {0};

int main () {
scanf ("%d", & N);
fact[0] = 1;
for (int i = 1; i <= N; i ++)
fact[i] = fact[i - 1] * i % MOD;
for (int i = 1; i <= N; i ++)
F[i] = G[i] = power (2ll, 1ll * i * (i - 1) >> 1) * power (fact[i], MOD - 2);
G[0] ++;
inverse (N, G, invG);
NTT (F, invG, N, N);
for (int i = 1; i <= N; i ++) {
if (i == 1)
answer[i] = 1;
else if (i == 2)
answer[i] = - 1;
else
answer[i] = fact[i - 1] * power (2ll, 1ll * i * (i - 1) / 2ll - i) % MOD * power (F[i] * fact[i] % MOD, MOD - 2) % MOD;
}
for (int i = 1; i <= N; i ++)
printf ("%lld\n", answer[i]);

return 0;
}

/*
4
*/