#P5450. [THUPC 2018] 淘米神的树
[THUPC 2018] 淘米神的树
Description
Lovely Tommy has a tree. In this tree, only vertices and are black, and all other vertices are white.
Each time, Tommy can recolor a black vertex to red, and then recolor all white vertices adjacent to into black. In the end, all vertices will be recolored to red.
Let the -th vertex be recolored to red as the -th one; then is a permutation of to . Tommy wants you to help him find how many different there are.
Input Format
Each input file contains only one testdata.
-
The first line contains three positive integers separated by spaces, representing the number of vertices of the tree and the indices of the initial black vertices.
-
The next lines each contain two positive integers , describing an edge in the tree.
The vertices of the tree are numbered starting from .
Output Format
Output line:
- One integer, representing the number of different permutations modulo .
4 1 2
1 2
2 3
3 4
4
Hint
Constraints
It is guaranteed that .
Copyright Information
From the 2018 Tsinghua University Programming Contest and Collegiate Invitational (THUPC2018). Thanks to Pony.ai for supporting this contest.
Resources such as editorials can be found at https://github.com/wangyurzee7/THUPC2018.
Translated by ChatGPT 5
京公网安备 11011102002149号