logo AlgoBeat OnlineJudge
登录 注册

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

内存限制:512 MiB 时间限制:1500 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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

Now he wants to start the depth-first search at the root. He wonders for each node , how many ways it can appear in the -th position of . The depth-first search order is the order of nodes visited during the depth-first search. A node appears in the -th () position in this order means it is visited after 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 , how many different s such that appears in the -th position. For each , compute the answer. Because the answer can be very large, output it modulo .

Following is a pseudo-code for the depth-first search on a rooted tree. After calling (), is the depth-first search order.

输入格式

The first line contains one integer , the number of vertices in the tree.

Each of the next lines describes an edge of the tree. Edge is denoted by two integers and , the labels of vertices it connects .

It is guaranteed that the given edges form a tree.

输出格式

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

样例

样例输入 1

5
1 2
1 3
3 4
3 5

样例输出 1

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