Studying Father's luogu blog

Studying Father's luogu blog

从零至灵,由壹达意

题解 CF1172B 【Nauuo and Circle】

posted on 2019-06-08 02:36:17 | under 题解 |

Unofficial Solution to this contest also available in Studying Father's Blog.


其实是个结论题。

答案为每个节点度数阶乘之积再乘 $ n $ 。

(官方题解也给出了一种树形DP的解法,当然这两种解法是完全等价的)

#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;
}