hdu 5329 Question for the Leader 枚举,划分图为k个联通的子图

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(1kn)  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(1n105) .

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 3
Hint
Case 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








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GDRetop

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值