#P7782. 「MCOI-Zero / AC6-M03」 Sipli Field
「MCOI-Zero / AC6-M03」 Sipli Field
Description
Given a tree with nodes and two constants .
For each node , find how many paths pass through and have length .
Input Format
The first line contains three integers .
The next line contains integers. The -th integer indicates that there is an undirected edge .
Output Format
Output lines, each containing one integer, representing the answer for the corresponding node.
5 1 3
1 1 2 2
7
9
4
4
4
Hint
Explanation for Sample 1:
- Paths passing through : 1-2, 1-3, 1-4, 1-5, 2-3, 4-3, 5-3.
- Paths passing through : 2-1, 2-3, 2-4, 2-5, 1-4, 1-5, 3-4, 3-5, 4-5.
- Paths passing through : 3-1, 3-2, 3-4, 3-5.
- Paths passing through : 4-1, 4-2, 4-3, 4-5.
- Paths passing through : 5-1, 5-2, 5-3, 5-4.
- Subtask 1 (3 pts): .
- Subtask 2 (7 pts): .
- Subtask 3 (10 pts): .
- Subtask 4 (10 pts): .
- Subtask 5 (15 pts): .
- Subtask 6 (15 pts): .
- Subtask 7 (20 pts): .
- Subtask 8 (20 pts): No special constraints.
For of the testdata, it holds that , .
Idea: _Solowing_ClCN, solution: _Solowing_ClCN, code: _Solowing_ClCN, data: _Solowing_ClCN.
Translated by ChatGPT 5
京公网安备 11011102002149号