博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[Poi2014]FarmCraft
阅读量:4961 次
发布时间:2019-06-12

本文共 3858 字,大约阅读时间需要 12 分钟。

题目描述

In a village called Byteville, there are   houses connected with N-1 roads. For each pair of houses, there is a unique way to get from one to another. The houses are numbered from 1 to  . The house no. 1 belongs to the village administrator Byteasar. As part of enabling modern technologies for rural areas framework,   computers have been delivered to Byteasar"s house. Every house is to be supplied with a computer, and it is Byteasar"s task to distribute them. The citizens of Byteville have already agreed to play the most recent version of FarmCraft (the game) as soon as they have their computers.
Byteasar has loaded all the computers on his pickup truck and is about to set out to deliver the goods. He has just the right amount of gasoline to drive each road twice. In each house, Byteasar leaves one computer, and immediately continues on his route. In each house, as soon as house dwellers get their computer, they turn it on and install FarmCraft. The time it takes to install and set up the game very much depends on one"s tech savviness, which is fortunately known for each household. After he delivers all the computers, Byteasar will come back to his house and install the game on his computer. The travel time along each road linking two houses is exactly 1 minute, and (due to citizens" eagerness to play) the time to unload a computer is negligible.
Help Byteasar in determining a delivery order that allows all Byteville"s citizens (including Byteasar) to start playing together as soon as possible. In other words, find an order that minimizes the time when everyone has FarmCraft installed.
mhy住在一棵有n个点的树的1号结点上,每个结点上都有一个妹子。
mhy从自己家出发,去给每一个妹子都送一台电脑,每个妹子拿到电脑后就会开始安装zhx牌杀毒软件,第i个妹子安装时间为Ci。
树上的每条边mhy能且仅能走两次,每次耗费1单位时间。mhy送完所有电脑后会回自己家里然后开始装zhx牌杀毒软件。
卸货和装电脑是不需要时间的。
求所有妹子和mhy都装好zhx牌杀毒软件的最短时间。

输入

The first line of the standard input contains a single integer N(2<=N<=5 00 000)  that gives the number of houses in Byteville. The second line contains N integers C1,C2…Cn(1<=Ci<=10^9), separated by single spaces; Ci is the installation time (in minutes) for the dwellers of house no. i.
The next N-1  lines specify the roads linking the houses. Each such line contains two positive integers a and b(1<=a<b<=N) , separated by a single space. These indicate that there is a direct road between the houses no. a and b.

输出

The first and only line of the standard output should contain a single integer: the (minimum) number of minutes after which all citizens will be able to play FarmCraft together.

样例输入

61 8 9 6 3 21 32 33 44 54 6

样例输出

11
树规+贪心搞一波。。
考试又考了贪心。。
先树规一下
处理出走完其子树所需要的时间和其子树完全下载完软件的时间

按dp数组排序贪心搞一搞就行了

#include 
#include
#include
#include
#define Max(x,y) (x)>(y)?(x):(y)#define ll long longusing namespace std;const int MAXN = 500005;int n,e=1,first[MAXN],size[MAXN],w[MAXN];ll val[MAXN],Judge,Ans,f[MAXN];bool vis[MAXN];vector
G[MAXN];vector
::iterator it; template
inline _t read(){ _t x=0,f=1; char ch=getchar(); for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-')f=-f; for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+(ch^48); return x*f;} struct edge{ int u,v,next;}a[MAXN*3]; void push(int u,int v){ a[e].u=u;a[e].v=v; a[e].next=first[u]; first[u]=e++;} inline int cmp(int x,int y){return f[x]-2*size[x]>f[y]-2*size[y];} void __dfs(int u,int fa){ size[u]=1; for(int i=first[u];i;i=a[i].next) if(a[i].v!=fa){ G[u].push_back(a[i].v); __dfs(a[i].v,u); size[u]+=size[a[i].v]; }} void dfs(int u){ size[u]=1;int num=0,cnt=0;f[u]=val[u]; for(int i=0;i
(); for(int i=1;i<=n;i++)val[i]=read
(),G[i].clear(); for(int i=1;i
(),v=read
(); push(u,v);push(v,u); } __dfs(1,0);dfs(1); printf("%lld\n",Max(f[1],val[1]+n*2-2));}

转载于:https://www.cnblogs.com/Cooook/p/7738498.html

你可能感兴趣的文章
node.js express配置允许跨域
查看>>
JSP EL表达式详细介绍(转)
查看>>
要想找出正好包含5个字符的名字
查看>>
用js把图片做的富有动态感,并对以后需要用着的属性进行封装
查看>>
ArcGIS Runtime For Android 100.3天地图不加载问题
查看>>
线性表
查看>>
【转】解决eclipse新导入工程无法run as server
查看>>
【转】struts1.2的action参数配置
查看>>
快速幂&快速乘
查看>>
WebLogic 12c 多节点Cluster静默安装
查看>>
win8中如何禁用屏幕旋转的快捷键
查看>>
Solution 23: 判断矩形和圆是否相交
查看>>
Qt And MFC Mouse Over Tips
查看>>
JSP/Servlet 中的汉字编码问题
查看>>
《构建之法》(十)
查看>>
django之信号
查看>>
[noip2013]货车运输(kruskal + 树上倍增)
查看>>
简单工厂模式
查看>>
#hashMap冲突原理#详细
查看>>
基于单片机定时器---年月日时分秒的算法
查看>>