CF1172B 题解
Suzt_ilymtics · · 题解
代码写起来和 SF 的是差不多的,不过理解的角度略有不同。
首先,因为它在一个环上,我们可以固定任何方案中的任何一个点作为环的起点,所以最后方案数要
然后我们考虑依次去加边。
考虑加一条边
考虑
就比如下面这张图,当前已经连了三条边,
然后再从
最后放代码:
#include<bits/stdc++.h>
#define int long long
#define orz cout<<"tyy YYDS!!!\n"
using namespace std;
const int MAXN = 2e5+5;
const int mod = 998244353;
int n, ans = 1;
int du[MAXN];
signed main()
{
n = read();
for(int i = 1; i <= n; ++i) du[i] = 1;
for(int i = 1, u, v; i < n; ++i) {
u = read(), v = read();
ans = ans * du[u] % mod * du[v] % mod;
du[u] ++, du[v] ++;
}
printf("%lld\n", ans * n % mod);
return 0;
}