#P5333. [JSOI2019] 神经网络
[JSOI2019] 神经网络
Description
After a Martian is born, its neural network can be seen as a forest consisting of several undirected trees $\{T_1(V_1, E_1), T_2(V_2, E_2),\ldots T_m(V_m, E_m)\}$. As the Martian grows older, the number of neural connections keeps increasing. Initially, the set of newly grown connections in the neural network is . The neural network grows according to the following rule:
- If nodes and belong to different undirected trees and respectively (), then should contain the edge .
Finally, after no more neural network connections can grow, the connections between nodes in the neural network can be regarded as an undirected graph , where
$$V=V_1\cup V_2\cup \ldots \cup V_m,E=E_1\cup E_2\cup \ldots \cup E_m\cup E^\ast$$Martians make decisions by creating cycles in . For different external inputs, Martians will create different neural connection cycles and thus produce different responses. To understand how complex Martian behavior patterns are, JYY decides to compute the number of Hamiltonian cycles in .
A Hamiltonian cycle of is a simple cycle that starts from the first node of the first tree, visits every other node in exactly once, and then returns to the first node of the first tree.
Input Format
The first line contains , the number of undirected trees in the Martian neural network at the beginning.
Then there are parts, where the -th part describes the tree .
For , the first line contains , the number of nodes in the tree . Assume .
In the next lines, each line contains two integers , meaning there is a tree edge between nodes and (), i.e., .
Output Format
Since the number of Hamiltonian cycles can be very large, output a non-negative integer equal to the answer modulo .
2
3
1 2
1 3
2
1 2
12
Hint

Translated by ChatGPT 5
京公网安备 11011102002149号