2015 Multi-University Training Contest 1 hdu 5290 Bombing plan
Bombing plan
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 416 Accepted Submission(s): 96
Now kingdom Y is going to bomb kingdom X. Every city of kingdom X has its own value W. If city i was to be bombed, then all the cities that lie within the distance W(i) from city i would be destroyed as well. The king of kingdom Y wants to know the minimum bombing time that can destroy all the cities in kingdom X. Could you help him?
In each test case:
First line: an integer n(n<=10^5) indicating the number of city
Second line:contain n numbers w[i](0<=w[i]<=100) ,indicating that the value of city[i],
Next n - 1 lines: each contains two numbers ui and vi, (1 ≤ ui,vi<=n), indicates that there’s one road connecting city ui and vi.
转移方程:
不炸毁u点
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct arc {
int to,next;
arc(int x = ,int y = -) {
to = x;
next = y;
}
} e[maxn<<];
int head[maxn],d[maxn],n,tot;
void add(int u,int v) {
e[tot] = arc(v,head[u]);
head[u] = tot++;
e[tot] = arc(u,head[v]);
head[v] = tot++;
}
int q[maxn],p[maxn],de[maxn],hd,tl;
int F[maxn][],G[maxn][],A[maxn][],B[maxn][];
int main() {
int u,v,a,b;
while(~scanf("%d",&n)) {
for(int i = ; i <= n; ++i)
scanf("%d",d+i);
tot = ;
memset(head,-,sizeof head);
memset(G,-,sizeof G);
memset(F,-,sizeof F);
memset(A,-,sizeof A);
memset(B,-,sizeof B);
for(int i = ; i < n; ++i) {
scanf("%d%d",&u,&v);
add(u,v);
}
p[q[hd = tl = ] = ] = -;
while(hd <= tl) {
de[u = q[hd++]] = ;
for(int i = head[u]; ~i; i = e[i].next) {
if(e[i].to != p[u]) {
p[e[i].to] = u;
q[++tl] = e[i].to;
}
}
}
while(tl >= ) {
v = q[tl--];
if(p[v] >= ) de[p[v]] = max(de[p[v]],de[v]+);
if(!de[v]) {
if(d[v] >= ) {
F[v][d[v]] = ;
for(int i = ; i < d[v]; ++i) A[v][i] = -;
for(int i = d[v]; i < ; ++i) A[v][i] = ;
}
G[v][] = ;
for(int i = ; i <= ; ++i) B[v][i] = ;
continue;
} for(int i = ; i <= min(,de[v]); ++i) {
G[v][i] = ;
for(int j = head[v]; ~j; j = e[j].next) {
u = e[j].to;
if(u == p[v]) continue;
a = B[u][i-];
b = A[u][];
if(a == - && b == -) {
G[v][i] = -;
break;
}
if(a == -) a = maxn;
if(b == -) b = maxn;
G[v][i] += min(a,b);
}
if(G[v][i] == -) break;
} if(d[v] >= ) {
F[v][d[v]] = ;
for(int i = head[v]; ~i; i = e[i].next) {
u = e[i].to;
if(u == p[v]) continue;
a = A[u][];
b = -;
if(d[v] > ) b = B[u][d[v]-];
if(a == - && b == -) {
F[v][d[v]] = -;
break;
}
if(a == -) a = maxn;
if(b == -) b = maxn;
F[v][d[v]] += min(a,b);
}
} for(int i = head[v]; ~i; i = e[i].next) {
u = e[i].to;
if(u == p[v]) continue;
for(int j = ; j <= ; ++j)
if(F[u][j] != -) {
int tmp = ;
for(int k = head[v]; ~k; k = e[k].next) {
if(e[k].to != u && e[k].to != p[v]) {
a = A[e[k].to][];
b = -;
if(j - >= ) b = B[e[k].to][j-];
if(a == - && b == -) {
tmp = -;
break;
}
if(a == -) a = maxn;
if(b == -) b = maxn;
tmp += min(a,b);
}
}
if(tmp != - && (F[v][j-] == - || F[v][j-] > F[u][j] + tmp))
F[v][j-] = F[u][j] + tmp;
}
}
A[v][] = F[v][];
B[v][] = G[v][];
for(int i = ; i <= ; ++i) {
A[v][i] = A[v][i-];
if(F[v][i] != - && (A[v][i] == - || A[v][i] > F[v][i]))
A[v][i] = F[v][i];
B[v][i] = B[v][i-];
if(G[v][i] != - && (B[v][i] == - || B[v][i] > G[v][i]))
B[v][i] = G[v][i];
}
}
int ret = -;
for(int i = ; i <= ; ++i)
if(F[][i] != - && (ret == - || ret > F[][i]))
ret = F[][i];
printf("%d\n",ret);
}
return ;
}
/*
5
1 1 1 1 1
1 2
2 3
3 4
4 5
*/
2015 Multi-University Training Contest 1 hdu 5290 Bombing plan的更多相关文章
- hdu 5290 Bombing plan
http://acm.hdu.edu.cn/showproblem.php?pid=5290 题意: 一棵树,每个点有一个权值wi,选择点i即可破坏所有距离点i<=wi的点,问破坏所有点 最少需 ...
- 2015 Multi-University Training Contest 8 hdu 5390 tree
tree Time Limit: 8000ms Memory Limit: 262144KB This problem will be judged on HDU. Original ID: 5390 ...
- 2015 Multi-University Training Contest 8 hdu 5383 Yu-Gi-Oh!
Yu-Gi-Oh! Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: ...
- 2015 Multi-University Training Contest 8 hdu 5385 The path
The path Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ID: 5 ...
- 2015 Multi-University Training Contest 3 hdu 5324 Boring Class
Boring Class Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 2015 Multi-University Training Contest 3 hdu 5317 RGCDQ
RGCDQ Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- 2015 Multi-University Training Contest 10 hdu 5406 CRB and Apple
CRB and Apple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- 2015 Multi-University Training Contest 10 hdu 5412 CRB and Queries
CRB and Queries Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- 2015 Multi-University Training Contest 6 hdu 5362 Just A String
Just A String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
随机推荐
- 利用请求的JSON数据创建图形图层
先看效果图: 包含三个部分:信息窗口(标题是要素的某个属性信息,其余是感兴趣的属性信息).图上图形按照某一属性大小不一显示,图例 1.创建底图用于存放以上三部分: "esri/Map&quo ...
- debian 9 安装无线网卡
#添加源 echo "deb http://httpredir.debian.org/debian/ stretch main contrib non-free" >> ...
- Eigen下载安装
首先提供Eigen的两个重要网站 官方网站 下载地址 1.下载 wget http://bitbucket.org/eigen/eigen/get/3.3.5.tar.gz 2.解压缩 tar -zx ...
- 线性回归(regression)
简介 回归分析只涉及到两个变量的,称一元回归分析.一元回归的主要任务是从两个相关变量中的一个变量去估计另一个变量,被估计的变量,称因变量,可设为Y:估计出的变量,称自变量,设为X. 回归分析就是要找出 ...
- [terry笔记]Python字符串
如下学习python的字符串用法. print(dir(str)) ['__add__', '__class__', '__contains__', '__delattr__', '__dir__', ...
- java中的hachcode方法
哈希表这个数据结构想必大多数人都不陌生,而且在很多地方都会利用到hash表来提高查找效率.在Java的Object类中有一个方法: public native int hashCode(); 根据这个 ...
- maven规定的目录
Maven规定的目录结构 若要使用Maven,那么项目的目录结构必须符合Maven的规范 ,如写一个使用Spring的Web项目就需要引入大量的jar包.一个项目Jar包的数量之多往往让我们瞠目结舌, ...
- nodejs是一个平台,是平台
node.js是用javascript来写服务器代码的平台
- 怎样制作C#安装程序
近期须要制作一个C#安装.在网上找了一些资料发现都不是非常完整,最后自己综合了一些资料,而且通过亲自检測,最后成功完毕C#打包成安装程序(打包成最简单的一种安装程序.假设须要更高的功能请自己在开发). ...
- Unity3d修炼之路:用Mesh绘制一个Cube
#pragma strict function Awake(){ var pMeshFilter : MeshFilter = gameObject.AddComponent(typeof(MeshF ...