#P9264. [PA 2022] Drzewa rozpinające
[PA 2022] Drzewa rozpinające
Problem Description
This problem is translated from PA 2022 Round 5 Drzewa rozpinające.
You are given an integer sequence of length : . Based on this sequence, you can generate an undirected graph with vertices: between vertices and (for ), there are distinguishable edges connecting these two vertices. Your task is to compute the number of spanning trees of this graph. If, for two trees, one of them contains an edge that does not exist in the other, then these two trees are considered different. Since the number of spanning trees is very large, output it modulo .
Input Format
The first line contains an integer , representing the length of the integer sequence.
The second line contains integers , representing the sequence.
Output Format
Output one integer on a single line, representing the number of spanning trees of the generated graph modulo .
4
1 2 3 4
24
Hint
For of the testdata, the Constraints are:
, .
Translated by ChatGPT 5