「ARC106F」Figures

$Link$

给定一个 $n$ 个点的无向图,第 $i$ 个点有 $d_i$ 个接口,每条边连接两个不同的点的接口,每个接口只能被一条边连接。问这张图的生成树个数,对 $998244353$ 取模。

$2\le n\le 2\times10^5,1\le d_i<998244353$。

gugugu…

$code$

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
#include <iostream>
#include <cstdlib>
#include <cstdio>
#define ll long long
using namespace std;
inline int read()
{
int f = 1, x = 0;
char ch;

do{
ch = getchar();
if (ch == '-')
f = -1;
}while(ch < '0' || ch > '9');
do{
x = x * 10 + ch - '0';
ch = getchar();
}while(ch >= '0' && ch <= '9');
return f * x;
}
const int N = 2e5;
const int mod = 998244353;

int n;
int ans = 1;
ll ssum;

inline int pow(int x, int y)
{
int sum = 1;

while (y) {
if (y & 1)
sum = 1ll * sum * x % mod;
x = 1ll * x * x % mod;
y >>= 1;
}
return sum;
}
inline int C(int x, ll y)
{
if (x > y)
return 0;
int sum = 1, summ = 1;

for (ll i = y - x + 1; i <= y; i++)
sum = 1ll * (i % mod) * sum % mod;
for (int i = 1; i <= x; i++)
summ = 1ll * i * summ % mod;
return 1ll * sum * pow(summ, mod - 2) % mod;
}
int main()
{
n = read();
for (int i = 1; i <= n; i++) {
int x = read();
if (i <= n - 2)
ans = 1ll * ans * i % mod * x % mod;
else
ans = 1ll * ans * x % mod;
ssum += x - 1;
}

ans = 1ll * ans * C(n - 2, ssum) % mod;

printf("%d\n", ans);
return 0;
}