CF1172B.Nauuo and Circle
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 nodes and n−1 edges. The nodes are numbered from 1 to n.
Nauuo wants to draw a tree on the circle, the nodes of the tree should be in 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 elements. A permutation of n elements is a sequence of integers p1,p2,…,pn in which every integer from 1 to n appears exactly once.
After a permutation is chosen Nauuo draws the i-th node in the 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, can you help her?
It is obvious that whether a permutation is valid or not does not depend on which n points on the circle are chosen.
Nauuo 是一位喜欢画圆的女孩。
一天,她画了一个圆,并想在圆上画一棵树。
这棵树是一棵由 n 个节点和 n−1 条边构成的连通无向图。节点编号为 1 到 n。
Nauuo 想将这棵树画在圆上:树的每个节点必须放置在圆上 n 个互不相同的点处,且所有边均以直线段绘制,且两两之间互不相交。
“互不相交”是指:任意两条边要么没有公共点,要么其唯一公共点是这两条边的公共端点。
Nauuo 计划使用一个 n 元排列来完成绘图。一个 n 元排列是指一个整数序列 p1,p2,…,pn,其中 1 到 n 的每个整数恰好出现一次。
选定一个排列后,Nauuo 将第 i 个节点画在圆上的第 pi 个位置(即按顺时针或逆时针顺序标号的第 pi 个点),然后连接对应节点画出所有边。
题目给出了一棵具体的树,Nauuo 想知道:有多少个 n 元排列能使所画出的树满足上述规则(即所有边为直线段且互不相交)?她只需要知道答案对 998244353 取模的结果,你能帮她吗?
显然,一个排列是否合法,与圆上具体选取哪 n 个点无关。
输入格式
The first line contains a single integer n (2≤n≤2⋅105) — the number of nodes in the tree.
Each of the next n−1 lines contains two integers u and v (1≤u,v≤n), denoting there is an edge between u and v.
It is guaranteed that the given edges form a tree.
第一行包含一个整数 n(2≤n≤2⋅105)——树中节点的数量。
接下来的 n−1 行每行包含两个整数 u 和 v(1≤u,v≤n),表示节点 u 与节点 v 之间存在一条边。
保证给定的边构成一棵树。
输出格式
The output contains a single integer — the number of permutations suitable to draw the given tree on a circle satisfying the rule, modulo 998244353.
输出包含一个整数——满足在圆上绘制给定树并符合该规则的排列数量,对 998244353 取模。
输入输出样例
输入#1
4 1 2 1 3 2 4
输出#1
16
输入#2
4 1 2 1 3 1 4
输出#2
24
说明/提示
Example 1
All valid permutations and their spanning trees are as follows.

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

Example 2
Every permutation leads to a valid tree, so the answer is 4!=24.
示例 1
所有有效的排列及其对应的生成树如下所示。

以下是一个无效排列的示例:边 (1,3) 和 (2,4) 发生了交叉。

示例 2
每个排列均对应一棵有效树,因此答案为 4!=24。
输入解题思路,AI测评打分。不知道怎么写?