Question for the Leader
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 308 Accepted Submission(s): 59
Problem Description
JRY is the leader of a village. He has
n
lands, and there are
n
roads connecting them. There is at most one road connecting two lands and all lands are connected.
Now, JRY wants to divided the n lands into k 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 k(1≤k≤n) he can choose.
Now, JRY wants to divided the n lands into k 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 k(1≤k≤n) he can choose.
Input
There are multiple testcases, the sum of
n
is less then
106
.
For each test case, the first line contains one integer n(1≤n≤105) .
The next line contains n integers, the i -th integer ai means that there is an edge between i and ai . It is guaranteed that the graph doesn't contain self loops and multiple edges.
For each test case, the first line contains one integer n(1≤n≤105) .
The next line contains n integers, the i -th integer ai means that there is an edge between i and ai . 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
k
.
Sample Input
6 2 3 4 5 6 1 6 2 4 2 3 4 3
Sample Output
4 3HintCase 1 : k = 1,2,3,6 Case 2: k = 1,3,6
题目:
把图划分为大小都为k的子图,子树内相互联通
题解直接黏贴解题报告了。
做法,求出基环。算出每个基环上的结点的子树的结点数,算出不在基环上的结点的子树的结点数
如果对于n % k == 0
算出不在基环上的结点就几个子树是k的倍数。得到F1
然后对于基环的点,任意点作为起点算出前缀和。对于每个前缀和%k。查看0-k-1中哪个数模数的到的次数最多。得到F2
判断F1+F2 == n/k