【题目链接】 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. Problem L. Visual Cube(杭电多校2018年第三场+模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6330 题目: 题意:给你长宽高,让你画出一个正方体. 思路:模拟即可,湘潭邀请赛热身赛原题,不过比那个 ...

  2. 计蒜客 Goldbach Miller_Rabin判别法(大素数判别法)

    题目链接:https://nanti.jisuanke.com/t/25985 题目: Description: Goldbach's conjecture is one of the oldest ...

  3. WinRAR分割超大文件

    在自己的硬盘上有一个比较大的文件,想把它从网上通过E-Mail发送给朋友时,却发现对方的收信服务器不能够支持那么大的文件……,这时即使用ZIP等压缩软件也无济于事,因为该文件本身已经被压缩过了.于是许 ...

  4. hdu 1863 畅通工程 (并查集+最小生成树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1863 畅通工程 Time Limit: 1000/1000 MS (Java/Others)    M ...

  5. face_recognition 人脸识别报错

    [root@localhost examples]# python facerec_from_video_file.py RuntimeError: module compiled against A ...

  6. 【DataScience学习笔记】Coursera课程《数据科学家的工具箱》 约翰霍普金斯大学——Week3 Conceptual Issues课堂笔记

    Coursera课程<数据科学家的工具箱> 约翰霍普金斯大学 Week3 Conceptual Issues Types of Questions Types of Data Scienc ...

  7. git subtree:无缝管理通用子项目

    移动互联网的爆发以及响应式页面的尴尬症,开发web和mobile项目成为了标配,当然实际情况下,会有更多的项目. 多项目开发对于前端来说是个很大的挑战✦ 重复,重复的前端架构,重复的前端依赖,重复的工 ...

  8. [ python ] 下划线的意义和一些特殊方法

    Python用下划线 Python用下划线为变量前缀和后缀制定特殊变量 _xxx 不能用 'from module import *' 导入__xxx__ 系统定义名字__xxx 类中的私有变量名 核 ...

  9. Java学习笔记(三)——静态导入,package-info,Fall-through

    [前面的话] 算是真正的放松了好几天时间,没有看任何书,没有任何任务,今天是过完年后的第一天上班时间,我又开始了我的学习之路,感觉还没有老,怎么心态越来越平静了,进入工作状态,就好好努力工作,新的一年 ...

  10. AC日记——The Shortest Path in Nya Graph hdu 4725

    4725 思路: 拆点建图跑最短路: 代码: #include <cstdio> #include <cstring> #include <iostream> #i ...