8670: Expected Inversions

内存限制:128 MB 时间限制:3 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

For an integer sequence a1,...,an of length n, its inversion number inv(a) is defined as the number of integer pairs (i,j) such that 1i<jn and ai>aj.

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 uu to the father of uu.

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 du. We call (d1,d2,...,dn) 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 ii 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 QP with P,Q being integers and 

Q0(mod998244353). There is exactly one integer R[0,998244353) that satisfies QRP(mod998244353). Print this R as the answer.

输入格式

The first line of input contains a single integer T1T10), indicating the number of test cases. Then T test cases follow.

The first line of each test case contains a single integer n((1n105), indicating the number of vertices in the tree. Each of the next n-1 lines contains two integers u,v(1u,vn), 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 orderwhen rooting the tree at vertex ii.

输入样例 复制

1
3
1 2
1 3

输出样例 复制

499122177
1
2