FarmCraft[POI2014]
题目描述
输入
输出
样例输入
6
1 8 9 6 3 2
1 3
2 3
3 4
4 5
4 6
样例输出
11
提示
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int sj=;
int n,c[sj],h[sj],e,a1,a2,f[sj],jg;
int p[sj],fa[sj];
struct B
{
int ne,v;
}b[sj*];
void add(int x,int y)
{
b[e].v=y;
b[e].ne=h[x];
h[x]=e++;
}
int bj(int x,int y)
{
return x>y?x:y;
}
struct D
{
int num,vl;
}d[sj];
int comp(const D&a,const D&b)
{
return a.vl>b.vl;
}
void dfs(int x,int ge)
{
int temp=ge,ww=;
for(int i=h[x];i!=-;i=b[i].ne)
if(b[i].v!=fa[x])
{
fa[b[i].v]=x;
dfs(b[i].v,temp);
f[x]+=f[b[i].v]+;
d[temp].vl=p[b[i].v];
d[temp].num=b[i].v;
temp++;
}
p[x]=c[x]-f[x];
if(p[x]<) p[x]=;
sort(d+ge,d+temp,comp);
for(int i=ge;i<temp;i++)
{
ww+=f[d[i].num];
p[x]=bj(p[x],p[d[i].num]-(f[x]-ww));
ww+=;
}
}
void init()
{
scanf("%d",&n);
memset(h,-,sizeof(h));
for(int i=;i<=n;i++) scanf("%d",&c[i]);
for(int i=;i<n;i++)
{
scanf("%d%d",&a1,&a2);
add(a1,a2);
add(a2,a1);
}
dfs(,);
}
int main()
{
init();
jg=bj(c[],p[])+*n-;
printf("%d",jg);
return ;
}
farmcraft
你应该超越自己,走得更远,登得更高,直至群星已在你脚下
FarmCraft[POI2014]的更多相关文章
- [补档][Poi2014]FarmCraft
[Poi2014]FarmCraft 题目 mhy住在一棵有n个点的树的1号结点上,每个结点上都有一个妹子. mhy从自己家出发,去给每一个妹子都送一台电脑,每个妹子拿到电脑后就会开始安装zhx牌杀毒 ...
- [BZOJ 3829][POI2014] FarmCraft
先贴一波题面... 3829: [Poi2014]FarmCraft Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 421 Solved: 197[ ...
- 【BZOJ3829】[Poi2014]FarmCraft 树形DP(贪心)
[BZOJ3829][Poi2014]FarmCraft Description In a village called Byteville, there are houses connected ...
- BZOJ3829[Poi2014]FarmCraft——树形DP+贪心
题目描述 In a village called Byteville, there are houses connected with N-1 roads. For each pair of ho ...
- 【bzoj3829】[Poi2014]FarmCraft 贪心
原文地址:http://www.cnblogs.com/GXZlegend/p/6826667.html 题目描述 In a village called Byteville, there are ...
- [POI2014][树形DP]FarmCraft
题目 In a village called Byteville, there are houses connected with N-1 roads. For each pair of houses ...
- BZOJ3829 : [Poi2014]FarmCraft
d[x]表示走完x的子树并回到x所需的时间 f[x]表示从走到x开始计时,x子树中最晚的点安装完的最早时间 d[x]=sum(d[i]+2),i是x的孩子 f[x]的计算比较复杂: 考虑将x的各棵子树 ...
- [Poi2014]FarmCraft 树状dp
对于每个点,处理出走完其子树所需要的时间和其子树完全下载完软件的时间 易证,对于每个点的所有子节点,一定优先选择差值大的来给后面的时间 树规+贪心. #include<cstdio> #i ...
- BZOJ3829 [Poi2014]FarmCraft 【树形dp】
题目链接 BZOJ3829 题解 设\(f[i]\)为从\(i\)父亲进入\(i\)之前开始计时,\(i\)的子树中最晚装好的时间 同时记\(siz[i]\)为节点\(i\)子树大小的两倍,即为从父亲 ...
随机推荐
- Discuz搜索改为指向帖子
安装的版本是DiscuzX2.5,搜索的时候发现默认指向的是门户里的文章搜索,但程序都没有安装门户,只有论坛,所以不能搜索文章. 在网上找了半天终于找到修改的办法了. <input name=& ...
- java 类变量的初始化
有代码如下:class Price{ final static Price INSTANCE = NEW Price(2.8); static double initPrice = 20; ...
- mysql中group by和order by同时使用无效的替代方案
前言 最近一年由于工作需要大部分使用的都是NoSql数据库,对关系型数据库感觉越来越陌生,一个由group by和order by 引发的血案由此而生.在此做个记录,以备不时之需. 需求 首先,看一下 ...
- 针对Oracle数据库表中的数据的常见操作
1.查询表中所有数据 select * from 表名; 例:select * from stu; 2.查询的同时修改表中数据 select * from 表名 for update; 例:sele ...
- 设备像素比dpr介绍
首先介绍一下概念 devicePixelRatio其实指的是window.devicePixelRatio window.devicePixelRatio是设备上物理像素和设备独立像素(device- ...
- 基于邮件系统的远程实时监控系统的实现 Python版
人生苦短,我用Python~ 界内的Python宣传标语,对Python而言,这是种标榜,实际上,Python确实是当下最好用的开发语言之一. 在相继学习了C++/C#/Java之后,接触Python ...
- 全选与单选chekbox的自定义实现(angular框架)
2017年7月4日,我原本可以像其他同时一样早点回家,玩几把王者荣耀,但是我没有,因为我选择留下来,写一篇博客. 项目中经常性的会遇到什么点击"全选"按钮,勾中所有"单选 ...
- 如何使用slice,substr代替substring(原创)
//写这个是为了加深对substring和slice的理解 substring: 任何一个参数小于0,都会被替换成0.两个参数,最小值会被当做start,最大值当做end. 参数 描述 start 必 ...
- oracle预定义角色
角色是相关权限的集合,使用角色能够简化权限的管理.简而言之就是oracle可以事先把一系列权限集中在一起(角色),打包赋予给用户,那么用户就具有了角色的一系列权限. oracle预定义角色有25种,它 ...
- django Modelform
前言: 为什么要用form去验证呢? 我们提交的是form表单,在看前端源码时如果检查到POST URL及我们提交的字段,如果没有验证我们是否可以直接POST数据到URL,后台并没有进行校验,直接处理 ...