#abc323g. G - Inversion of Tree
G - Inversion of Tree
Score : points
问题描述
给定一个由 的排列 。
对于每个 ,找出满足以下条件的有 个顶点(编号为 到 )的树的数量,计算结果对 取模。
- 在树中直接通过边相连的顶点对 中,恰好有 对满足 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a permutation of .
For each , find the number, modulo , of trees with vertices numbered to that satisfy the following condition.
- Among the pairs of vertices that are directly connected by an edge in the tree, exactly pairs satisfy .
Constraints
- is a permutation of .
Input
The input is given from Standard Input in the following format:
Output
For each , print the number, modulo , of trees that satisfy the condition, with spaces in between.
Sample Input 1
3
1 3 2
Sample Output 1
1 2 0
The answer for is : the tree with edges connecting vertices and . Indeed, and .
The answer for is : the tree with edges connecting vertices and , and another with edges connecting vertices and . Indeed, in the tree with edges connecting vertices and , we have , .
Sample Input 2
10
3 1 4 10 8 6 9 2 7 5
Sample Output 2
294448 2989776 12112684 25422152 30002820 20184912 7484084 1397576 108908 2640
update @ 2024/3/10 01:45:30