题解 CF1172B 【Nauuo and Circle】
StudyingFather · · 题解
设
首先容易发现为了不出现相交的情况,各子树一定对应一个连续的区间。
于是得到如下转移方程:
上面这个式子的含义比较显然:对于根节点,其
最终答案为
稍微化简一下上面的式子,就会发现答案为每个节点度数阶乘之积再乘
#include <iostream>
#include <algorithm>
#define MOD 998244353
using namespace std;
int t[200005];
int main()
{
int n;
cin>>n;
long long ans=n;
for(int i=1;i<n;i++)
{
int u,v;
cin>>u>>v;
t[u]++,t[v]++;
ans=ans*t[u]%MOD*t[v]%MOD;
}
cout<<ans<<endl;
return 0;
}