CF1172B Nauuo and Circle题解 思维

文章讨论了如何利用动态规划解决诺诺在圆上画树的问题,考虑了节点排列和边不交叉的条件,给出了一个关于节点数量n的排列计数问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Nauuo and Circle

传送门

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 n n n nodes and n − 1 n-1 n1 edges. The nodes are numbered from 1 1 1 to n n n.

Nauuo wants to draw a tree on the circle, the nodes of the tree should be in n n n 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 n n n elements. A permutation of n n n elements is a sequence of integers p 1 , p 2 , … , p n p_1,p_2,\ldots,p_n p1,p2,,pn in which every integer from 1 1 1 to n n n appears exactly once.

After a permutation is chosen Nauuo draws the i i i-th node in the p i p_i pi-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 998244353 998244353 998244353, can you help her?

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

Input

The first line contains a single integer n n n ( 2 ≤ n ≤ 2 ⋅ 1 0 5 2\le n\le 2\cdot 10^5 2n2105) — the number of nodes in the tree.

Each of the next n − 1 n-1 n1 lines contains two integers u u u</

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值