hdu 5329 Question for the Leader 枚举,划分图为k个联通的子图
来源:互联网 发布:ebscohost外文数据库 编辑:程序博客网 时间:2024/06/07 09:07
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 then 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 manyk(1≤k≤n) he can choose.
Now, JRY wants to divided the
Furthermore, he wants to know how many
Input
There are multiple testcases, the sum of n is less then 106 .
For each test case, the first line contains one integern(1≤n≤105) .
The next line containsn 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
The next line contains
Output
For each testcase print a single integer - the number of ways to choose the integer k .
Sample Input
62 3 4 5 6 162 4 2 3 4 3
Sample Output
43HintCase 1 :k = 1,2,3,6Case 2:k = 1,3,6
题目:
把图划分为大小都为k的子图,子树内相互联通
题解直接黏贴解题报告了。
做法,求出基环。算出每个基环上的结点的子树的结点数,算出不在基环上的结点的子树的结点数
如果对于n % k == 0
算出不在基环上的结点就几个子树是k的倍数。得到F1
然后对于基环的点,任意点作为起点算出前缀和。对于每个前缀和%k。查看0-k-1中哪个数模数的到的次数最多。得到F2
判断F1+F2 == n/k
0 0
- hdu 5329 Question for the Leader 枚举,划分图为k个联通的子图
- hdu 5329 Question for the Leader
- hdu 5329 Question for the Leader
- HDOJ 5329 Question for the Leader
- 2015多校第四场1003 hdu 5329 Question for the Leader
- hdu5329(2015多校4)--Question for the Leader
- HDU 5713 K个联通块 状压dp枚举子集 (2016百度之星复赛)
- [HDU 4997 Biconnected] 无向图的边双联通子图计数 状压DP
- HDU 5713 K个联通块(状压DP)
- hdu 4908 以k为中位数的子序列计数
- hdu 3394 图的双联通分量
- HDU5713 K个联通块
- 无向图的联通分量NEUACM1134: Searching for TwoBee
- hdu 4352 数位dp(最长上升子序列的长度为k的个数)
- hdu 5713 K个联通块 2016百度之星复赛1002 DP
- HDU 5713 & 2016"百度之星" 复赛(Astar Round3)1002 k个联通块
- HDU-5713-K个联通块 状压dp 计数技巧 去重技巧
- HDU 5713 K个联通块【状压计数dp……补集转化?
- bzoj-3143 游走
- 九度oj 1445
- 黑马程序员——自学java基础第一天
- 【Spring Security】之一:Eclipse搭建Spring Security项目
- AndroidDevTools
- hdu 5329 Question for the Leader 枚举,划分图为k个联通的子图
- 栈的压入、弹出序列
- 随手记
- Linxu命令与文件的搜索 - which, whereis, locate, find
- 进入最后的沟通阶段, 更需要一如既往地保持冷静的心态和真诚的态度, 继续负责地贡献自己的力量。
- Git本地基础操作
- Java之反射机制【入门版(4),实例解析】
- 7.27--7.31总结
- 最小二乘法(自我理解+自我熟悉)(3)