Nauuo and Circle
https://codeforces.com/contest/1173/problem/D
题意:一颗n点的生成树,n点都在圆上,求使得边不相交的排列种数(排列相同,圆上绝对位置不同视作不同排列)
题解:DFS+思维+DP+组合数学
1、对于除1号节点作为父节点的子节点以外,都有在父节点左边和右边两种情况,因此以这一父节点的子节点排列种数等于(子节点数量+1)*子节点数量的排列数;
证明:
对于子节点的任何一种排列方式,父节点都有子节点数量+1种位置可以放置
2、除1号节点以外,某一子树排列种数等于这一子树的根节点的子节点数+1的阶乘*所有以这一子树的根节点的子节点为根节点的子树排列种类的乘积;
3、ans=生成树的排列种数*n;
/*
*@Author: STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=200000+10;
const int M=100000+10;
const int MOD=998244353;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
int ans,cnt,flag,temp,sum;
ll ins[N];
int vis[N];
vector<int>G[N];
ll dfs(int u){
int sz=G[u].size();
vis[u]=1;
ll res=ins[sz];
for(int i=0;i<sz;i++){
int v=G[u][i];
if(!vis[v])res=(res*dfs(v))%MOD;
}
//cout<<res<<endl;
return res;
}
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
//ios::sync_with_stdio(false);
//cin.tie(0);
//cout.tie(0);
//scanf("%d",&t);
//while(t--){
scanf("%d",&n);
ins[0]=1;
for(int i=1;i<=n;i++)ins[i]=(ins[i-1]*i)%MOD;
for(int i=1;i<n;i++){
scanf("%d%d",&u,&v);
G[u].push_back(v);
G[v].push_back(u);
}
cout<<dfs(1)*n%MOD<<endl;
//}
#ifdef DEBUG
printf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif
//cout << "Hello world!" << endl;
return 0;
}