当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7255:Expected Inversions

题目描述
For an integer sequence $a_1,...,a_n$ of length $n$, its inversion number $\mathrm{inv}(a)$ is defined as the number of integer pairs $(i,j)$ such that $1\leq i < j\leq n$ and $a_i > a_j$.

For a given rooted tree of $n$ nodes (with vertices numbered from $1$ to $n$), a **DFS procedure** on the tree is as following.

- During the process, we maintain a **current vertex**, namely $u$, and a **set of visited vertices**, namely $M$.
- Let the root of the tree be $x$. Initially, $u=x$ and $M=\{x\}$.
- Repeat the following process until $M$ contains all vertices:
- - If there is at least one child vertex of $u$ that is not in $M$, randomly choose one among those vertices equiprobably (namely $v$). Set $u$ to $v$ and add $v$ to $M$.
- Otherwise, set $u$ to the father of $u$.

For each $u=1,...,n$, we record the number of vertices in $M$ when $u$ is added to $M$ (including $u$). Let this number be $d_u$. We call $(d_1,d_2,...,d_n)$ a **DFS order**. As **DFS procedure** is non-deterministic, the resulting **DFS order** may vary as well. Assume that each decision in the **DFS procedure** is independent.

You are given an unrooted tree of $n$ vertices, with vertices numbered from $1$ to $n$. For each $i=1,...,n$, compute the expected inversion number of the **DFS order** when rooting the tree at $i$ and start a **DFS procedure**. To avoid precision errors, print the answer modulo $998244353$.

You are given $T$ independent test cases. Solve each of them.

**How to compute non-integers modulo $998244353$:** It can be proved that the answer to this problem can always be written as a fraction $\dfrac{P}{Q}$ with $P,Q$ being integers and $Q\not\equiv 0\pmod{998244353}$. There is exactly one integer $R\in [0,998244353)$ that satisfies $QR\equiv P\pmod{998244353}$. Print this $R$ as the answer.
输入解释
The first line of input contains a single integer $T(1\leq T\leq 10)$, indicating the number of test cases. Then $T$ test cases follow.

The first line of each test case contains a single integer $n(1\leq n\leq 10^5)$, indicating the number of vertices in the tree. Each of the next $n-1$ lines contains two integers $u,v(1\leq u,v\leq n)$, indicating an edge on the tree. It is guaranteed that the input edges form a tree.
输出解释
For each test case, print the answers in $n$ lines. The $i$-th line should contain the expected inversion number of the **DFS order** when rooting the tree at vertex $i$.
输入样例
1
3
1 2
1 3
输出样例
499122177
1
2

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7255

最后修改于 2022-09-15T06:17:38+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
6000/3000MS(Java/Others) 524288/524288K(Java/Others)