BZOJ1304: [CQOI2009]叶子的染色
来源:互联网 发布:sql注入点判断 编辑:程序博客网 时间:2024/04/28 16:34
可以证明根向任意方向移动一格,答案不变,所以根取哪个点都行
然后treedp
code:
#include<set>#include<map>#include<deque>#include<queue>#include<stack>#include<cmath>#include<ctime>#include<bitset>#include<string>#include<vector>#include<cstdio>#include<cstdlib>#include<cstring>#include<climits>#include<complex>#include<iostream>#define ll long longusing namespace std;const int maxn = 11000;int n,m;struct edge{ int y,nex; edge(){} edge(const int _y,const int _nex){y=_y;nex=_nex;}}a[maxn<<1]; int len,fir[maxn];inline void ins(const int x,const int y){a[++len]=edge(y,fir[x]);fir[x]=len;}int f[maxn][2],c[maxn];void dfs(const int x,const int ff){ f[x][0]=f[x][1]=1; if(x<=m) { f[x][c[x]^1]=maxn; return; } for(int k=fir[x];k;k=a[k].nex) { const int y=a[k].y; if(y!=ff) { dfs(y,x); f[x][0]+=min(f[y][0]-1,f[y][1]); f[x][1]+=min(f[y][1]-1,f[y][0]); } }}int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=m;i++) scanf("%d",&c[i]); for(int i=1;i<n;i++) { int x,y; scanf("%d%d",&x,&y); ins(x,y); ins(y,x); } dfs(m+1,0); printf("%d\n",min(f[m+1][0],f[m+1][1])); return 0;}
阅读全文
0 0
- CQOI2009 BZOJ1304 叶子的染色
- bzoj1304: [CQOI2009]叶子的染色
- BZOJ1304: [CQOI2009]叶子的染色
- bzoj1304 [CQOI2009]叶子的染色 dfs+树形dp
- 1304: [CQOI2009]叶子的染色
- [CQOI2009] 叶子的染色 - 贪心或动规
- BZOJ 1304: [CQOI2009]叶子的染色 树形DP
- BZOJ 1304: [CQOI2009]叶子的染色 树形dp
- 【jzoj1010】【CQOI2009】【叶子的颜色】【树型动态规划】
- 【CQOI2009】【C++心路历程39】叶子的颜色【贪心】
- BZOJ 1304 叶子的染色 树形DP
- 叶子的分页类
- 一片叶子的飞翔
- 叶子形状的loading
- 叶子形状的loading
- 叶子
- 叶子
- 叶子
- 使用 REST 接口获取订阅下虚拟机信息
- [FFT] HDU 1402
- Nosql数据库之mongodb c++使用实例
- 使用maya.cmds加载和卸载插件
- SpringMVC源码解析-LocaleResolver
- BZOJ1304: [CQOI2009]叶子的染色
- 欢迎使用CSDN-markdown编辑器
- 通过jsonp跨域问题制作简单的天气
- 如何处理托管磁盘 OS 盘无法创建虚拟机的问题
- java设计模式03
- Servlet配置数据库连接池
- SpringMVC里拦截器preHandle里的参数意思
- 返回xml或json过长时被nginx截断的解决办法
- ie6+左右浮动图片案例