[cerc2017J]Justified Jungle
题目大意:删去k条边,树变为相等个点的连通分量,求所有正整数k。
解题关键:树dp,不必求因子。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxn 1000006
int head[maxn],cnt,siz[maxn],v[maxn],n;
struct edge{
int to,nxt;
}e[maxn<<];
void add_edge(int u,int v){
e[cnt].to=v;
e[cnt].nxt=head[u];
head[u]=cnt++;
}
void dfs(int u,int fa){
siz[u]=;
for(int i=head[u];i!=-;i=e[i].nxt){
int v=e[i].to;
if(v==fa) continue;
dfs(v,u);
siz[u]+=siz[v];
}
v[siz[u]]++;
}
bool check(int x){
x++;
if(n%x) return ;
int w=n/x,sum=;
for(int i=w;i<=n;i+=w) sum+=v[i];
return sum==x;
}
int main(){
memset(head,-,sizeof head);
scanf("%d",&n);
for(int i=;i<n-;i++){
int a,b;
scanf("%d%d",&a,&b);
add_edge(a,b);
add_edge(b,a);
}
dfs(,-);
for(int i=;i<=n;i++){
if(check(i)) printf("%d ",i);
}
return ;
}
[cerc2017J]Justified Jungle的更多相关文章
- GYM - 101620 J.Justified Jungle
题意: 给出一棵树,删掉其中一些边,要求生成的每个子树节点数一样.输出所有可以删掉的边数. 题解: 以节点1为根,预处理每个子树的大小.对于每个n的因数x,还需满足子树为他倍数的点够n/x个,那么删的 ...
- 2017-2018 ACM-ICPC, Central Europe Regional Contest (CERC 17)
A. Assignment Algorithm 按题意模拟即可. #include<stdio.h> #include<iostream> #include<string ...
- 2017 CERC
2017 CERC Problem A:Assignment Algorithm 题目描述:按照规则安排在飞机上的座位. solution 模拟. 时间复杂度:\(O(nm)\) Problem B: ...
- CREC 2017
A:Assignment Algorithm #include <bits/stdc++.h> using namespace std; ][]; ][],n,m,ans=,A,B,l=, ...
- poj 1251 Jungle Roads (最小生成树)
poj 1251 Jungle Roads (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000 ...
- Jungle Roads[HDU1301]
Jungle Roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- Jungle Roads
Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid ...
- POJ 1251 Jungle Roads (prim)
D - Jungle Roads Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Su ...
- hdu 1301 Jungle Roads 最小生成树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 The Head Elder of the tropical island of Lagrish ...
随机推荐
- python中的excel操作
一. Excel在python中的应用 存测试数据 有的时候大批量的数据,我们需要存到数据库中,在测试的时候才能用到.测试的时候就从数据库中读取出来.这点是非常重要的! 存测试结果 二. Excel中 ...
- 如何显示u盘的隐藏的文件
方法/步骤 从U盘属性可以看出,U盘的大量空间被占用,U盘内有很多文件. 点击查看选项卡下的“选项”按钮 切换到中间的“查看”选项卡 取消勾选“隐藏受保护的操作系统文件” 在弹出的警告对话框, ...
- cassandra集群环境搭建——注意seeds节点,DHT p2p集群管理难道初始化都应如此吗?
解压cassandra的安装包后可以查看主要的配置文件,都在conf/目录下,conf/cassandra.yaml比较重要,其中需要着重注意的有以下一些配置项: cluster_name: 'TC0 ...
- java快捷键大全
存盘 Ctrl+s(肯定知道) 注释代码 Ctrl+/ 取消注释 Ctrl+(Eclipse3已经都合并到Ctrl+/了) 代码辅助 Alt+/ 快速修复 Ctrl+1 代码格式化 Ctrl+Shif ...
- Django 基础 web框架本质
Web框架本质 我们可以这样理解:所有的Web应用本质上就是一个socket服务端,而用户的浏览器就是一个socket客户端. 这样我们就可以自己实现Web框架了. import socket sk ...
- 23 Python 面向对象
面向过程 VS 面向对象 面向过程的程序设计的核心是过程(流水线式思维),过程即解决问题的步骤,面向过程的设计就好比精心设计好一条流水线,考虑周全什么时候处理什么东西. 优点是:极大的降低了写程序的复 ...
- 轮廓Outline|表格Table实例
1.使用outline属性在元素周围画一条线. border:red solid thin; outline:#00ff00 dotted thick; outline-style:dotted|da ...
- Java使用指南(1)—— Java下载和安装
Java下载 1.在Oracle的官网中找到相应的
- 搭建了一个Apache+Php+MySQL的服务器。要如何通过Apache发布网站使得其他的电脑可以通过局域网访问?
源址: 1.网站的代码放在文件夹“www”下: 2.配置apache允许他人访问网站:在wamp/apache/apache版本/conf的httpd.conf文件修改代码如下: Optio ...
- .net core结合Consul集群&Docker实现服务治理
实战中的asp.net core结合Consul集群&Docker实现服务治理 https://www.cnblogs.com/guolianyu/p/9614050.html 0.目录 整体 ...