B. Nauuo and Circle

26 篇文章 0 订阅
5 篇文章 0 订阅

题目链接:http://codeforces.com/problemset/problem/1172/B

Nauuo is a girl who loves drawing circles.

One day she has drawn a circle and wanted to draw a tree on it.

The tree is a connected undirected graph consisting of nn nodes and n−1n−1 edges. The nodes are numbered from 11 to nn.

Nauuo wants to draw a tree on the circle, the nodes of the tree should be in nn distinct points on the circle, and the edges should be straight without crossing each other.

"Without crossing each other" means that every two edges have no common point or the only common point is an endpoint of both edges.

Nauuo wants to draw the tree using a permutation of nn elements. A permutation of nn elements is a sequence of integers p1,p2,…,pnp1,p2,…,pn in which every integer from 11 to nn appears exactly once.

After a permutation is chosen Nauuo draws the ii-th node in the pipi-th point on the circle, then draws the edges connecting the nodes.

The tree is given, Nauuo wants to know how many permutations are there so that the tree drawn satisfies the rule (the edges are straight without crossing each other). She only wants to know the answer modulo 998244353998244353, can you help her?

It is obvious that whether a permutation is valid or not does not depend on which nn points on the circle are chosen.

Input

The first line contains a single integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the number of nodes in the tree.

Each of the next n−1n−1 lines contains two integers uu and vv (1≤u,v≤n1≤u,v≤n), denoting there is an edge between uu and vv.

It is guaranteed that the given edges form a tree.

Output

The output contains a single integer — the number of permutations suitable to draw the given tree on a circle satisfying the rule, modulo 998244353998244353.

Examples

input

Copy

4
1 2
1 3
2 4

output

Copy

16

input

Copy

4
1 2
1 3
1 4

output

Copy

24

Note

Example 1

All valid permutations and their spanning trees are as follows.

Here is an example of invalid permutation: the edges (1,3)(1,3) and (2,4)(2,4) are crossed.

Example 2

Every permutation leads to a valid tree, so the answer is 4!=244!=24.

题意:给一棵树,然后要用节点画一个圈,顶点之间的边不能相交。

思路:画画图就可以知道有同一个父节点的子节点必须要连续,然后就是算组合数,考虑一个顶点他有x个子节点,那么字节点的排列数有x!,然后父亲节点可以放x+2个位置(除顶点外),但每个顶点都可以作为第一个开始的数,所以最后要乘以个n;所以公式为n*de[i](i从1到n),de[i]为每个节点的度。

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#define LL long long

using namespace std;
const int maxn=2e5+100;
const int mod=998244353;

LL fac[maxn];
int de[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    fac[0]=1;
    for(int i=1;i<=n;i++)
    {
        fac[i]=fac[i-1]*i;
        fac[i]%=mod;
    }
    for(int i=1;i<n;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        de[u]++;
        de[v]++;
    }
    LL ans=n;
    for(int i=1;i<=n;i++)
    {
        ans=ans%mod*fac[de[i]]%mod;
        ans%=mod;
    }
    printf("%lld\n",ans);
    return 0;
}

反思:组合数还是太弱。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值