【树形dp】Bzoj3391 [Usaco2004 Dec]Tree Cutting网络破坏
Description
Solution
树形dp裸题,刷水好欢乐。
Code
#include<cstdio>
const int maxn=1e5+; int n,f[maxn],d[maxn];
int head[maxn],e[maxn*],nxt[maxn*],cnt;
int adde(int u,int v){
e[++cnt]=v;nxt[cnt]=head[u];head[u]=cnt;
e[++cnt]=u;nxt[cnt]=head[v];head[v]=cnt;
} int dfs(int p,int u){
d[u]=;
for(int i=head[u];i;i=nxt[i]){
int v=e[i];
if(v==p) continue;
dfs(u,v);
d[u]+=d[v];
if(d[v]>n/) f[u]=;
}
if(n-d[u]>n/) f[u]=;
} int main(){
scanf("%d",&n);
int u,v; for(int i=;i<n;i++){
scanf("%d%d",&u,&v);
adde(u,v);
}
dfs(,); for(int i=;i<=n;i++)
if(!f[i]) printf("%d\n",i);
return ;
}
【树形dp】Bzoj3391 [Usaco2004 Dec]Tree Cutting网络破坏的更多相关文章
- BZOJ3391: [Usaco2004 Dec]Tree Cutting网络破坏
3391: [Usaco2004 Dec]Tree Cutting网络破坏 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 47 Solved: 37[ ...
- 【枚举】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网络破坏(树形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 显然判断每个点只需要判断子树是否小于等于n/2即可 那么我们虚拟一个根,然后计算每个子树的si ...
- BZOJ 3391: [Usaco2004 Dec]Tree Cutting网络破坏(搜索)
这道直接遍历一遍求出每个点的子节点数目就行了= = CODE: #include<cstdio>#include<iostream>#include<algorithm& ...
- 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> ...
随机推荐
- 讲解Oracle面试过程中常见的二十个问题
1.冷备份和热备份的不同点以及各自的优点 解答:热备份针对归档模式的数据库,在数据库仍旧处于工作状态时进行备份.而冷备份指在数据库关闭后,进行备份,适用于所有模式的数据库.热备份的优点在于当备 ...
- WebAPP移动前端性能优化规范和设计指导
- 8 个最好的 jQuery 树形 Tree 插件
由于其拥有庞大,实用的插件库,使得 jQuery 变得越来越流行.今天将介绍一些最好的 jQuery 树形视图插件,具有扩展和可折叠的树视图.这些都是轻量级的,灵活的 jQuery 插件,它将一个无序 ...
- js 逻辑运算符优化
运算符的代码优化,可以精简代码,提高代码可读性 下面主要讨论下逻辑运算符与 &&, 或||. 示例: 假设对成长速度显示规定如下: 成长速度为5显示1个箭头: 成长速度为10显示2个箭 ...
- add-apt-repository出Exception问题
参考:http://blog.sina.com.cn/s/blog_5388923c0100nu8h.html 症状: xxxx@xxxxx:~$ sudo add-apt-repository pp ...
- Django-CKedtior图片找不到的问题
从Django Packages站点上找到这个CKeditor集成组件:https://github.com/shaunsephton/django-ckeditor 按照官方的install方法安装 ...
- C#WebService 出现No 'Access-Control-Allow-Origin' header is present on the requested resource
C#WebService 出现No 'Access-Control-Allow-Origin' header is present on the requested resource 解决办法: 在c ...
- websocket通信 实现java模拟一个client与webclient通信
发文原由: 熟悉socket通信的同学,对于socket模拟server与client,实现相互通信, 或者使用websocket与java模拟的websocket服务器通信(比如一个聊天室),对于这 ...
- [译文]Domain Driven Design Reference(二)—— 让模型起作用
本书是Eric Evans对他自己写的<领域驱动设计-软件核心复杂性应对之道>的一本字典式的参考书,可用于快速查找<领域驱动设计>中的诸多概念及其简明解释. 其它本系列其它文章 ...
- CRM客户关系管理系统(九)
第九章.filter_horizontal优化和kingadmin删除功能 9.1.filter_horizontal优化 (1)添加Choose ALL 和Remove ALL table_obj_ ...