【题目链接】 http://www.lydsy.com/JudgeOnline/problem.php?id=3391

【题目大意】

  给定一棵树,求分支size均不大于一半点数的点

【题解】

  递归的同时计算各个分支size,如果出现大于一半点数的则给这个点打上标记
  最后输出没有标记的点即可。

【代码】

#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int N=10010;
int size[N],mark[N],n;
vector<int> v[N];
void dfs(int x,int fx){
size[x]=1,mark[x]=1;
for(int i=0;i<v[x].size();i++){
int y=v[x][i];
if(y!=fx){
dfs(y,x);
if(size[y]*2>n)mark[x]=0;
size[x]+=size[y];
}
}if((n-size[x])*2>n)mark[x]=0;
}
int main(){
while(~scanf("%d",&n)){
for(int i=1;i<n;i++){
int x,y;
scanf("%d%d",&x,&y);
v[x].push_back(y);
v[y].push_back(x);
}dfs(1,0);
int flag=1;
for(int i=1;i<=n;i++)if(mark[i]){printf("%d\n",i);flag=0;}
if(flag)puts("NONE");
}return 0;
}

BZOJ 3391 [Usaco2004 Dec]Tree Cutting网络破坏(树形DP)的更多相关文章

  1. BZOJ 3391: [Usaco2004 Dec]Tree Cutting网络破坏( dfs )

    因为是棵树 , 所以直接 dfs 就好了... ---------------------------------------------------------------------------- ...

  2. BZOJ 3391 [Usaco2004 Dec]Tree Cutting网络破坏:dfs【无根树 节点分枝子树大小】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3391 题意: 给你一棵无根树,求分支size均不大于一半点数的点. 题解: 假定1为根. ...

  3. BZOJ 3391: [Usaco2004 Dec]Tree Cutting网络破坏(搜索)

    这道直接遍历一遍求出每个点的子节点数目就行了= = CODE: #include<cstdio>#include<iostream>#include<algorithm& ...

  4. 3391: [Usaco2004 Dec]Tree Cutting网络破坏

    3391: [Usaco2004 Dec]Tree Cutting网络破坏 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 76  Solved: 59[ ...

  5. 【BZOJ】3391: [Usaco2004 Dec]Tree Cutting网络破坏(dfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3391 显然判断每个点只需要判断子树是否小于等于n/2即可 那么我们虚拟一个根,然后计算每个子树的si ...

  6. BZOJ3391: [Usaco2004 Dec]Tree Cutting网络破坏

    3391: [Usaco2004 Dec]Tree Cutting网络破坏 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 47  Solved: 37[ ...

  7. 【树形dp】Bzoj3391 [Usaco2004 Dec]Tree Cutting网络破坏

    Description     约翰意识到贝茜建设网络花费了他巨额的经费,就把她解雇了.贝茜很愤怒,打算狠狠报 复.她打算破坏刚建成的约翰的网络.    约翰的网络是树形的,连接着N(1≤N≤1000 ...

  8. 【枚举】bzoj3391 [Usaco2004 Dec]Tree Cutting网络破坏

    #include<cstdio> using namespace std; #define N 10001 int n; int v[N<<1],first[N],next[N ...

  9. BZOJ 3391 Tree Cutting网络破坏

    不想写. #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> ...

随机推荐

  1. .NET Core Data Access

    .NET Core was released a few months ago, and data access libraries for most databases, both relation ...

  2. hdu 2795 Billboard(线段树+单点更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 Billboard Time Limit: 20000/8000 MS (Java/Others ...

  3. ImageView设置边框 以及内部图片居中显示 在AndroidStudio中添加shape.xml文件

    效果如图 边框设置:shape文件 <shape xmlns:android="http://schemas.android.com/apk/res/android"> ...

  4. nodejs安装express以后,使用express显示不是内部或外部命令

    1.问题描述 在命令窗口通过npm install -g express 安装express以后,通过express -e express新建工程失败,提示express不是内部或外部命令 2.解决方 ...

  5. MS16-032提权正确方法

    原版MS16-032提权会Spawn一个System Shell出来,只能通过Remote Desktop获取.这里修改exploit,直接反弹Shell.注意MS16-032依赖 thread ha ...

  6. linux安装lamp

    github https://github.com/zblogcn/zblogphp Installation If your server system: CentOS yum -y install ...

  7. GitHub创建项目入门学习

    第一次创建git项目注意事项还是挺多了,这里就写个操作步骤,方便以后查看. 网页部分 1.打开自己的主页,点击“New repository”创建远程仓库. 2.填写信息 本地部分 前提: 下载git ...

  8. 构造函数、原型对象prototype、实例、隐式原型__proto__的理解

    (欢迎一起探讨,如果有什么地方写的不准确或是不正确也欢迎大家指出来~) PS: 内容中的__proto__可能会被markdown语法导致显示为proto. 建议将构造函数中的方法都定义到构造函数的原 ...

  9. [New learn] 网络基础-apache本地服务搭建(支持php)

    1.简介 无网不利,无网不胜.对于移动应用来说离开网络那和咸鱼有什么分别?所以对于开发者来说更要学习好网络开发的技术. 2.搭建apache本地服务器 1.在finder中显示影藏的用户文件夹 fin ...

  10. HDU-2819

    Swap Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...