#P9669. [ICPC 2022 Jinan R] DFS Order 2

    ID: 9025 Type: RemoteJudge 1500ms 512MiB Tried: 0 Accepted: 0 Difficulty: 6 Uploaded By: Tags>2022O2优化背包树形 dpICPC济南

[ICPC 2022 Jinan R] DFS Order 2

题目描述

Prof. Pang has a rooted tree that is rooted at vertex 11 and has nn nodes. These nn nodes are numbered from 11 to nn.

Now he wants to start the depth-first search at the root. He wonders for each node vv, how many ways it can appear in the jj-th position of depth-first search order\textbf{depth-first search order}. The depth-first search order is the order of nodes visited during the depth-first search. A node appears in the jj-th (1jn1\le j\le n) position in this order means it is visited after j1j-1 other nodes. Because sons of a node can be iterated in arbitrary order, multiple possible depth-first orders exist.

Prof. Pang wants to know for each node vv, how many different depth-first search order\textbf{depth-first search order}s such that vv appears in the jj-th position. For each v,j (1v,jn)v, j~(1 \le v, j \le n), compute the answer. Because the answer can be very large, output it modulo 998244353998244353.

Following is a pseudo-code for the depth-first search on a rooted tree. After calling main\textbf{main}(), dfs_order\texttt{dfs\_order} is the depth-first search order.

输入格式

The first line contains one integer n (1n500)n~(1\le n \le 500), the number of vertices in the tree.

Each of the next n1n-1 lines describes an edge of the tree. Edge ii is denoted by two integers uiu_i and viv_i, the labels of vertices it connects (1ui,vin,uivi)(1\le u_i,v_i\le n, u_i\neq v_i).

It is guaranteed that the given edges form a tree.

输出格式

For each vertex vv from 11 to nn, output one line containing nn integers modulo 998244353998244353. The jj-th integer in the vv-th line should be the number of different depth-first search orders such that vv appears in the jj-th position.

5
1 2
1 3
3 4
3 5
4 0 0 0 0
0 2 0 0 2
0 2 2 0 0
0 0 1 2 1
0 0 1 2 1