#P10013. [集训队互测 2023] Tree Topological Order Counting
[集训队互测 2023] Tree Topological Order Counting
Problem Description
Given a rooted tree with nodes, where node is the root, let the parent of be . You are also given a weight sequence of length .
A permutation of length is called a valid topological order of this tree if and only if .
For each node , define as the sum of over all valid topological orders of this tree.
Now, for , compute .
Input Format
The first line contains an integer , the number of nodes in the tree.
The second line contains integers. The -th integer denotes , describing the structure of the tree.
The third line contains integers. The -th integer denotes , describing the weight sequence.
Output Format
Output one line with integers. The -th integer denotes .
5
1 1 3 2
3 5 4 4 1
18 27 27 15 15
5
1 1 3 1
1 2 3 4 5
12 42 32 52 42
Hint
| Subtask | Special Constraint | Score | |
|---|---|---|---|
| None | |||
| A | |||
| None | |||
Special constraint A: .
Constraints for all testdata: , , .
Translated by ChatGPT 5