【树形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> ...
随机推荐
- DPDK virtio-user
PS:欢迎大家关注我的公众号:aCloudDeveloper,专注技术分享,努力打造干货分享平台,二维码在文末可以扫,谢谢大家. virtio-user 是 DPDK 针对特定场景提出的一种解决方案, ...
- linux系统安装mysql数据库
1.首先关闭linux的防火墙,执行命令 chkconfig iptables off 2.从mysql官网上下载自己适合的mysql版本https://dev.mysql.com/downloads ...
- db2 查新索引 主键 sql
1.查询主键 select * from sysibm.syskeycoluse where tbname='...' 2.查询索引 select * from sysibm.indexs where ...
- FreeMarker系列学习笔记
FreeMarker是一个非常优秀的模板引擎,这个模板引擎可用于任何场景,FreeMarker负责将数据模型中的数据合并到模板中,从而生成标准输出.FreeMarker可以提供昜好的团队协作,对于界面 ...
- 洛谷P1919 【模板】A*B Problem升级版 题解(FFT的第一次实战)
洛谷P1919 [模板]A*B Problem升级版(FFT快速傅里叶) 刚学了FFT,我们来刷一道模板题. 题目描述 给定两个长度为 n 的两个十进制数,求它们的乘积. n<=100000 如 ...
- BuautifulSoup4库详解
1.BeautifulSoup4库简介 What is beautifulsoup ? 答:一个可以用来从HTML 和 XML中提取数据的网页解析库,支持多种解析器(代替正则的复杂用法) 2.安装 p ...
- 原生Eclipse下Java服务器调试的一个问题
当你对Server的配置修改以后,最好到 workspacedir\.metadata\.plugins\org.eclipse.wst.server.core\tmp0目录下把缓存文件给删除了,否则 ...
- How To Install and Use Redis
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-Redis About Redis redis, dev ...
- (译)WebRTC实战: STUN, TURN, Signaling
http://xiaol.me/2014/08/24/webrtc-stun-turn-signaling/ 原文:WebRTC in the real world: STUN, TURN and s ...
- FatMouse' Trade -HZNU寒假集训
FatMouse' Trade FatMouse prepared M pounds of cat food, ready to trade with the cats guarding the wa ...