题意:

n个节点的树,删除一个点,得到的最大联通分支大小不大于总节点数的一半,求这样点的集合

分析:和上题一样

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define N 10010
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int dp[N],n,num[N],used[N];
vector<int>e[N];
int dfs(int root){
num[root]=;
used[root]=;
for(int i=;i<e[root].size();++i){
int son=e[root][i];
if(used[son])continue;
num[root]+=dfs(son);
dp[root]=max(dp[root],num[son]);
}
dp[root]=max(dp[root],n-num[root]);
return num[root];
}
int main()
{
int res[N];
while(~scanf("%d",&n)){
memset(dp,,sizeof(dp));
memset(used,,sizeof(used));
for(int i=;i<=n;++i)
e[i].clear();
int a,b;
for(int i=;i<n-;++i){
scanf("%d%d",&a,&b);
e[a].push_back(b);
e[b].push_back(a);
}
dfs();
int l=,f=;
for(int i=;i<=n;++i)
if(dp[i]<=n/){
f=;
printf("%d\n",i);
}
if(!f)printf("NONE\n");
}
return ;
}

POJ 2378-Tree Cutting(树形dp)的更多相关文章

  1. POJ 2378.Tree Cutting 树形dp 树的重心

    Tree Cutting Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4834   Accepted: 2958 Desc ...

  2. poj 2378 Tree Cutting 树形dp

    After Farmer John realized that Bessie had installed a "tree-shaped" network among his N ( ...

  3. POJ 2378 Tree Cutting 3140 Contestants Division (简单树形dp)

    POJ 2378 Tree Cutting:题意 求删除哪些单点后产生的森林中的每一棵树的大小都小于等于原树大小的一半 #include<cstdio> #include<cstri ...

  4. hdu 5909 Tree Cutting [树形DP fwt]

    hdu 5909 Tree Cutting 题意:一颗无根树,每个点有权值,连通子树的权值为异或和,求异或和为[0,m)的方案数 \(f[i][j]\)表示子树i中经过i的连通子树异或和为j的方案数 ...

  5. [poj3107/poj2378]Godfather/Tree Cutting树形dp

    题意:求树的重心(删除该点后子树最大的最小) 解题关键:想树的结构,删去某个点后只剩下它的子树和原树-此树所形成的数,然后第一次dp求每个子树的节点个数,第二次dp求解答案即可. 此题一开始一直T,后 ...

  6. POJ 2378 Tree Cutting (DFS)

    题目链接:http://poj.org/problem?id=2378 一棵树,去掉一个点剩下的每棵子树节点数不超过n/2.问有哪些这样的点,并按照顺序输出. dfs回溯即可. //#pragma c ...

  7. HDU - 5909 Tree Cutting (树形dp+FWT优化)

    题意:树上每个节点有权值,定义一棵树的权值为所有节点权值异或的值.求一棵树中,连通子树值为[0,m)的个数. 分析: 设\(dp[i][j]\)为根为i,值为j的子树的个数. 则\(dp[i][j\o ...

  8. HDU.5909.Tree Cutting(树形DP FWT/点分治)

    题目链接 \(Description\) 给定一棵树,每个点有权值,在\([0,m-1]\)之间.求异或和为\(0,1,...,m-1\)的非空连通块各有多少个. \(n\leq 1000,m\leq ...

  9. POJ 2378 Tree Cutting (树的重心,微变形)

    题意: 给定一棵树,n个节点,若删除点v使得剩下的连通快最大都不超过n/2,则称这样的点满足要求.求所有这样的点,若没有这样的点,输出NONE. 思路: 只需要拿“求树的重心”的代码改一行就OK了.因 ...

  10. POJ 2378 Tree Cutting 子树统计

    题目大意:给出一棵树.将树中的一个节点去掉之后,这棵树会分裂成一些联通块.求去掉哪些点之后.全部联通块的大小不超过全部节点的一半.并按顺序输出. 思路:基础的子树统计问题,仅仅要深搜一遍就能够出解.这 ...

随机推荐

  1. (转载)Cocos2dx-OpenGL ES2.0教程:编写自己的shader(2)

    在上篇文章中,我给大家介绍了如何在cocos2d-x里面绘制一个三角形,当时我们使用的是cocos2d-x引擎自带的shader和一些辅助函数.在本文中,我将演示一下如何编写自己的shader,同时, ...

  2. C# - dynamic 类型

    C#4引入dynamic关键字,定义变量时,可以不初始化它的值. dynamic类型仅在编译期间存在,在运行期间会被System.Object类型替代. dynamic myDynamicVar; m ...

  3. (转)[C++语法] 关键字typedef用法

    转自http://www.cnblogs.com/SweetDream/archive/2006/05/10/395921.html C/C++语言中的typedef相信大家已经不陌生,本文对C/C+ ...

  4. ./configure详解

    'configure'脚本有大量的命令行选项.对不同的软件包来说,这些选项可能会有变化,但是许多基本的选项是不会改变的.带上'--help'选项执行'configure'脚本可以看到可用的所有选项.尽 ...

  5. js获取fck值的代码方法

    引入js文件 <script type="text/javascript" src="${basePath}/FCKeditor/fckeditor.js" ...

  6. STL,ATL,WTL之间的联系和区别

    STL即 Standard Template Library (标准模板库) STL是惠普实验室开发的一系列软件的统称.它是由Alexander Stepanov.Meng Lee和David R M ...

  7. java:I/O 根据用户输入反馈信息

    import java.io.*; class userInputIO{ //Java中成员变量有默认初始化,也就是如果不显式设置初始值的话就会被初始化为其类型的默认值(0.false.null等). ...

  8. 解决 Your project contains error(s),please fix them before running your application问题

    原文地址: Android笔记:解决 Your project contains error(s),please fix them before running your application问题 ...

  9. Jdk5.0中出现的新特性

    掌握jdk5.0中出现的新特性1.泛型(Generics)2.增强的"for"循环(Enhanced For loop)3.自动装箱/自动拆箱(Autoboxing/unboxin ...

  10. 编码识别工具:hash-identifier

    hash-identifier的使用: 当不知道编码是什么类型的时候,可以通过kali系统中的hash工具判别,如下图所示, 在HASH后面输入要判别的编码内容,在后面的Possible Hashs中 ...