【树形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> ...
随机推荐
- 深入浅出Java concurrent
看 :http://www.blogjava.net/xylz/archive/2010/07/08/325587.html
- java 远程调试方法
http://wenku.baidu.com/link?url=5p3GZhPcfvM-VOzAFeCjbLeVv0OQrAGJh4HxirqImuK9VxPfmW243T_l5Plj6KdDZB1I ...
- Awesome Big Data List
https://github.com/onurakpolat/awesome-bigdata A curated list of awesome big data frameworks, resour ...
- element.dispatchEvent is not a function的解决
Firebug中的出错提示: element.dispatchEvent is not a function element.dispatchEvent(event); prototype.js (第 ...
- 利用HTML5,前端js实现图片压缩
http://blog.csdn.NET/qazwsx2345/article/details/21827553 主要用了两个HTML5的 API,一个file,一个canvas,压缩主要使用cnav ...
- jsoup 使用总结2--高级用法之 :gt(n)
jsoup 使用总结2--高级用法之 :gt(n) 大部分时候,我们使用jsoup解析网页的时候,都是直接找到某一类元素,或者按某种selector查询:具体使用方法可以参考jsoup官网文档 部分h ...
- Codeforces Round #479 (Div. 3) C. Less or Equal
题目地址:http://codeforces.com/contest/977/problem/C 题解:给一串数组,是否找到一个数x,找到k个数字<=x,找到输出x,不能输出-1.例如第二组,要 ...
- Jmeter(二十七)_Beanshell保存响应内容到本地
利用Jmeter-BeanShell PostProcessor可以提取响应结果并保存到本地文件,这种操作在jmeter做爬虫时非常有用,可以帮助你迅速的获取想要的内容到本地文件! 1:在本地新建一个 ...
- Roundcube 1.2.2 - Remote Code Execution
本文简要记述一下Roundcube 1.2.2远程代码执行漏洞的复现过程. 漏洞利用条件 Roundcube必须配置成使用PHP的mail()函数(如果没有指定SMTP,则是默认开启) PHP的mai ...
- JavaScript要点汇总——The Most Important
关于JavaScript的基础变量,运算符的详解以及基本的分支循环嵌套已经在 JS基础变量及JS中的运算符 JS中的循环分支嵌套 说过了,今天我们所说的是做网页中最长用到的东西.内容不算少,要有耐心, ...