[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 ...
随机推荐
- Eclipse_插件_05_自动下载jar包源码插件
一.Java Source Attacher 1.下载 官网:http://marketplace.eclipse.org/content/java-source-attacher#.U5RmTePp ...
- nyoj-253-LK的旅行(Graham算法和旋转卡壳)
题目链接 /* Name:nyoj-253-LK的旅行 Copyright: Author: Date: 2018/4/27 15:01:36 Description: zyj的模板 */ #incl ...
- UVA - 10934 Dropping water balloons (dp,逆向思维)
题目链接 题目大意:给你n个规格一样的气球和一栋大楼的高度,求最少试验几次能测出气球最高在哪一层掉下来不破. 如果这道题想用(dp[i][j]=用i个气球测出j高度的楼需要几次)来作为状态的话,那你就 ...
- nodejs 设置跨域访问
app.use(logger('dev')); app.use(express.json()); app.use(express.urlencoded({ extended: false })); a ...
- untra edit 自动补全
选择“高级-配置-编辑器-自动完成”,勾选“自动显示‘自动完成’对话框”,并在其中定义好“当输入x个字符”时,自动补全.
- Python修复图像文件后缀名
网上爬了很多图片,有很多错误. 有的不是图片文件,需要删除 有的后缀名错误,需要更正 用的的python脚本 #!/usr/bin/env python #-*- coding: utf-8 -*-# ...
- python模块导入的问题
从模块导入函数时,通常可以使用 import somemodule 或者 from somemodule import somefunction 或者 from somemodule import s ...
- PHP怎么把经过UTF-8编码的中文字符转换成正常的中文
问题的场景: html 为utf-8编码<meta http-equiv="Content-Type" content="text/html; charset=UT ...
- 蓝桥杯 基础练习 BASIC-22 FJ的字符串
基础练习 FJ的字符串 时间限制:1.0s 内存限制:512.0MB 问题描述 FJ在沙盘上写了这样一些字符串: A1 = “A” A2 = “ABA” A3 = “ABACABA” A4 = ...
- 自己写的highcharts级联(点击事件)
$.fn.extend({ Zhu: function (option) { var id = $(this).attr("id"); $('#' + id).highcharts ...