BZOJ3391: [Usaco2004 Dec]Tree Cutting网络破坏
3391: [Usaco2004 Dec]Tree Cutting网络破坏
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 47 Solved: 37
[Submit][Status]
Description
Input
Output
Sample Input
1 2
2 3
3 4
4 5
6 7
7 8
8 9
9 10
3 8
Sample Output
8
如果牛棚3或牛棚8被破坏,剩下的三个子网节点数将是5,2,2,没有超过5的.
来源信息
HINT
Source
题解:
类似与找重心,dfs一遍就行了。
代码:
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<string>
#define inf 1000000000
#define maxn 10000+10
#define maxm 500+100
#define eps 1e-10
#define ll long long
#define pa pair<int,int>
#define for0(i,n) for(int i=0;i<=(n);i++)
#define for1(i,n) for(int i=1;i<=(n);i++)
#define for2(i,x,y) for(int i=(x);i<=(y);i++)
#define for3(i,x,y) for(int i=(x);i>=(y);i--)
#define mod 1000000007
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}
return x*f;
}
int n,tot,head[maxn],a[maxn],f[maxn],s[maxn];
bool v[maxn];
struct edge{int go,next;}e[*maxn];
inline void insert(int x,int y)
{
e[++tot].go=y;e[tot].next=head[x];head[x]=tot;
e[++tot].go=x;e[tot].next=head[y];head[y]=tot;
}
void dfs(int x)
{
v[x]=;f[x]=;s[x]=;
for(int i=head[x],y;i;i=e[i].next)
if(!v[y=e[i].go])
{
dfs(y);
s[x]+=s[y];
f[x]=max(f[x],s[y]);
}
f[x]=max(f[x],n-s[x]);
if(f[x]<=n/)a[++a[]]=x;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
n=read();
for1(i,n-)insert(read(),read());
dfs();
if(!a[]){printf("NONE");return ;}
sort(a+,a+a[]+);
for1(i,a[])printf("%d\n",a[i]);
return ;
}
BZOJ3391: [Usaco2004 Dec]Tree Cutting网络破坏的更多相关文章
- 【树形dp】Bzoj3391 [Usaco2004 Dec]Tree Cutting网络破坏
Description 约翰意识到贝茜建设网络花费了他巨额的经费,就把她解雇了.贝茜很愤怒,打算狠狠报 复.她打算破坏刚建成的约翰的网络. 约翰的网络是树形的,连接着N(1≤N≤1000 ...
- 【枚举】bzoj3391 [Usaco2004 Dec]Tree Cutting网络破坏
#include<cstdio> using namespace std; #define N 10001 int n; int v[N<<1],first[N],next[N ...
- BZOJ 3391: [Usaco2004 Dec]Tree Cutting网络破坏( dfs )
因为是棵树 , 所以直接 dfs 就好了... ---------------------------------------------------------------------------- ...
- 3391: [Usaco2004 Dec]Tree Cutting网络破坏
3391: [Usaco2004 Dec]Tree Cutting网络破坏 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 76 Solved: 59[ ...
- 【BZOJ】3391: [Usaco2004 Dec]Tree Cutting网络破坏(dfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=3391 显然判断每个点只需要判断子树是否小于等于n/2即可 那么我们虚拟一个根,然后计算每个子树的si ...
- BZOJ 3391: [Usaco2004 Dec]Tree Cutting网络破坏(搜索)
这道直接遍历一遍求出每个点的子节点数目就行了= = CODE: #include<cstdio>#include<iostream>#include<algorithm& ...
- BZOJ 3391 [Usaco2004 Dec]Tree Cutting网络破坏(树形DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3391 [题目大意] 给定一棵树,求分支size均不大于一半点数的点 [题解] 递归的同 ...
- BZOJ 3391 [Usaco2004 Dec]Tree Cutting网络破坏:dfs【无根树 节点分枝子树大小】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3391 题意: 给你一棵无根树,求分支size均不大于一半点数的点. 题解: 假定1为根. ...
- BZOJ 3391 Tree Cutting网络破坏
不想写. #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> ...
随机推荐
- Object -C self -- 笔记
- 是实例方法,是用实例对象进行调用的:+ 是类方法,又称静态方法,是用类来调用的: @interface Person: NSObject { int _age; } - (void) setAge ...
- yii2使用Gii生成代码
本章节将介绍怎样使用 Gii 去自己主动生成 Web 网站经常使用功能的代码.使用 Gii 生成代码很easy,仅仅要依照 Gii 页面上的介绍输入正确的信息就可以. 贯穿本章节,你将会学到: 在你的 ...
- Excel 国家甘特图(多图)
前言 者必画的图.我找了非常久也没找到一个专门画甘特图比較好的软件.经过研究最终用Excel画出了甘特图.网上这个资料但是没有的哟! 效果 watermark/2/text/aHR0cDovL2Jsb ...
- 高效JQuery编码
缓存变量 DOM遍历是昂贵的,所以尽量将会重用的元素缓存. // 糟糕 h = $('#element').height(); $('#element').css('height',h-20); ...
- Android TableLayout 常用的属性介绍及演示
TableLayout经常用的属性是: 1.android:collapseColumns:以第0行为序,隐藏指定的列:把android:collapseColumns=0,2 意思是把第0和第2列隐 ...
- -bash: ulimit: open files: cannot modify limit: Operation not permitted
普通用户登录系统报错,提示: -bash: ulimit: open files: cannot modify limit: Operation not permitted. 处理方法: #vi /e ...
- Universal-Image-Loader 基本使用
简介 https://github.com/nostra13/Android-Universal-Image-Loader 项目的结构:每一个图片的加载和显示任务都运行在独立的线程中,除非这个图片缓存 ...
- android系统360浏览器使用append动态添加元素出现黑色错乱背景
去掉样式 backface-visibility:hidden;
- akka
akka学习 http://www.cnblogs.com/libaoheng/archive/2012/03/19/2406836.html
- DNN模块开发之利器篇:七种武器
我们在进行DNN模块开发时经常需要调用Dotnetnuke.dll中的方法函数,模块开发用到DNN的方法函数会让你的开发更加得心应手,下面我们就来介绍一下. 1) PortalModuleBase ...