代码写起来和 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;
}