#P10939. [2015杭电多校]Question for the Leader
[2015杭电多校]Question for the Leader
Question for the Leader
Problem Description
JRY is the leader of a village. He has lands, and there are roads connecting them. There is at most one road connecting two lands and all lands are connected. Now, JRY wants to divided the lands into disjoint sets of equal size, satisfying that one can move between any two lands belonging to the same set passing only through lands frome this set. Furthermore, he wants to know how many he can choose.
Input
There are multiple testcases, the sum of is less then . For each test case, the first line contains one integer . The next line contains integers, the -th integer means that there is an edge between and . It is guaranteed that the graph doesn't contain self loops and multiple edges.
Output
For each testcase print a single integer - the number of ways to choose the integer .
Sample Input
6
2 3 4 5 6 1
6
2 4 2 3 4 3
Sample Output
4
3
Hint
Case 1 : = 1,2,3,6 Case 2: = 1,3,6
Author
XJZX
Source
2015 Multi-University Training Contest 4