ZOJ 3684 Destroy
Destroy
This problem will be judged on ZJU. Original ID: 3684
64-bit integer IO format: %lld Java class name: Main
DJT country and CG country are always on wars.
This time DJT's King built a new information system over the whole country. He wants to know the message from the frontier immediately. There are numerous cities in DJT. In every city, there is one server of this system, and information is sending to the center continuously along a special data road. However, the data road is so expensive that there is one and only one road from one city to another city. Besides, the place of the center is a secret.
CG, of course, won't let DJT be happy for too long. CG is now planning to destroy DJT's new system. Due to some great undercover agents, CG has controlled some information about DJT's new system. The information CG has got:
- The center of DJT's new system would settle down in a city that for all other cities, the maximum distance should be the least.(you can make sure that only one city has the possibility to be the center)
- If no frontier city could send message back to the center, the system can be regard as destroyed. (a frontier city is a city that has only one road connecting to it)
- The length of each road.
- The power we need to destroy each road. (if we have a weapon of power max, we can destroy all the roads which it need the power less or equal to max)
Now, CG gives you a task: calculate the minimum power to destroy the system.
Input
There are multiple cases. For each case, one integer n (0 <= n <= 10000) indicating the number of cities in DJY country, cities are numbered from 1 to n, the next n-1 lines, one line contains four numbers describing one road, the two cities connected by the road, the length, and the power needed to destroy. The lengths are less than or equal to 10000. The powers are less than or equal to 100000000. All integers are nonnegative.
Output
For each case, output one number indicating the least power we need.
Sample Input
9
1 4 1 3
2 3 1 7
2 5 1 2
4 5 1 5
5 6 1 4
5 8 1 4
6 9 1 4
7 8 1 6
Sample Output
4
Source
Author
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = ;
struct arc{
int to,len,power,next;
arc(int x = ,int y = ,int z = ,int nxt =-){
to = x;
len = y;
power = z;
next = nxt;
}
}e[maxn<<];
int head[maxn],d[maxn],p[maxn],tot,n,S,T;
int dp[maxn];
void add(int u,int v,int len,int power){
e[tot] = arc(v,len,power,head[u]);
head[u] = tot++;
}
queue<int>q;
int bfs(int u){
memset(d,-,sizeof d);
memset(p,-,sizeof p);
d[u] = ;
while(!q.empty()) q.pop();
q.push(u);
int ret = u;
while(!q.empty()){
u = q.front();
q.pop();
if(d[u] > d[ret]) ret = u;
for(int i = head[u]; ~i; i = e[i].next){
if(d[e[i].to] == -){
d[e[i].to] = d[u] + e[i].len;
p[e[i].to] = u;
q.push(e[i].to);
}
}
}
return ret;
}
void dfs(int u,int fa){
int tmp = ;
dp[u] = 0x3f3f3f3f;
bool flag = false;
for(int i = head[u]; ~i; i = e[i].next){
if(e[i].to == fa) continue;
dfs(e[i].to,u);
tmp = max(tmp,min(e[i].power,dp[e[i].to]));
flag = true;
}
if(flag) dp[u] = min(dp[u],tmp);
}
int main(){
int u,v,L,P;
while(~scanf("%d",&n)){
memset(head,-,sizeof head);
int root = tot = ,mx = INF;
for(int i = ; i < n; ++i){
scanf("%d%d%d%d",&u,&v,&L,&P);
add(u,v,L,P);
add(v,u,L,P);
}
u = T = bfs(S = bfs());
while(~u){
int tmp = max(d[T] - d[u],d[u]);
if(tmp < mx){
mx = tmp;
root = u;
}
u = p[u];
}
dfs(root,-);
printf("%d\n",dp[root]);
}
return ;
}
ZOJ 3684 Destroy的更多相关文章
- ZOJ 3684 Destroy 树的中心
中心节点就是树的中心,2遍dfs求到树的直径.而中心一定在直径上,顺着直径找到中心就够了. 然后能够一遍树形DP找到最小值或者二分+推断是否訪问到叶子节点. #include <iostream ...
- 2014 Super Training #9 E Destroy --树的直径+树形DP
原题: ZOJ 3684 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3684 题意: 给你一棵树,树的根是树的中心(到其 ...
- ZOJ 2753 Min Cut (Destroy Trade Net)(无向图全局最小割)
题目大意 给一个无向图,包含 N 个点和 M 条边,问最少删掉多少条边使得图分为不连通的两个部分,图中有重边 数据范围:2<=N<=500, 0<=M<=N*(N-1)/2 做 ...
- zoj 3261 Connections in Galaxy War
点击打开链接zoj 3261 思路: 带权并查集 分析: 1 题目说的是有n个星球0~n-1,每个星球都有一个战斗值.n个星球之间有一些联系,并且n个星球之间会有互相伤害 2 根本没有思路的题,看了网 ...
- zoj 3620 Escape Time II dfs
题目链接: 题目 Escape Time II Time Limit: 20 Sec Memory Limit: 256 MB 问题描述 There is a fire in LTR ' s home ...
- 洛谷 P1197 BZOJ 1015 [JSOI2008]星球大战 (ZOJ 3261 Connections in Galaxy War)
这两道题长得差不多,都有分裂集合的操作,都是先将所有操作离线,然后从最后一步开始倒着模拟,这样一来,分裂就变成合并,也就是从打击以后最终的零散状态,一步步合并,回到最开始所有星球都被连为一个整体的状态 ...
- Backbone.js 中的Model被Destroy后,不能触发success的一个原因
下面这段代码中, 当调用destroy时,backbone会通过model中的url,向服务端发起一个HTTP DELETE请求, 以删除后台数据库中的user数据. 成功后,会回调触发绑定到dest ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
随机推荐
- 洛谷P3400 仓鼠窝(单调栈)
P3400 仓鼠窝 题目描述 萌萌哒的Created equal是一只小仓鼠,小仓鼠自然有仓鼠窝啦. 仓鼠窝是一个由n*m个格子组成的行数为n.列数为m的矩阵.小仓鼠现在想要知道,这个矩阵中有多少个子 ...
- 基于Web的Kafka管理器工具之Kafka-manager的编译部署详细安装 (支持kafka0.8、0.9和0.10以后版本)(图文详解)(默认端口或任意自定义端口)
不多说,直接上干货! 至于为什么,要写这篇博客以及安装Kafka-manager? 问题详情 无奈于,在kafka里没有一个较好自带的web ui.启动后无法观看,并且不友好.所以,需安装一个第三方的 ...
- RabbitMQ一:消息队列的认识
1异步处理 场景说明:用户注册后,需要发注册邮件和注册短信.传统的做法有两种1.串行的方式:2.并行方式. (1)串行方式:将注册信息写入数据库成功后,发送注册邮件,再发送注册短信.以上三个任务全部完 ...
- 常用的几个Dos命令-持续更新中
1.服务相关 (1).查看服务 C:\Windows\system32>net start 已经启动以下 Windows 服务: (2).启动服务 C:\Windows\system32> ...
- ValueError: multi-byte encodings are not supported
pyton解析xml时,报错 是因为编码的问题,把xml的头 <?xml version="1.0" encoding="gb2312"?> 改成 ...
- anime.js 实战:实现一个带有描边动画效果的复选框
在网页或者是APP的开发中,动画运用得当可以起到锦上添花的作用.正确使用动画,不但可以有助于用户理解交互的作用,还可以大大提高网页应用的魅力和使用体验.并且在现在的网页开发中,动画已经成为了一个设计的 ...
- 可以在一个html的文件当中读取另一个html文件的内容
1.IFrame引入,看看下面的代码 <IFRAME NAME="content_frame" width=100% height=30 marginwidth=0 marg ...
- Java集合框架源码(一)——hashMap
注:本人的源码基于JDK1.8.0,JDK的版本可以在命令行模式下通过java -version命令查看. 一首先我们来看一下HashMap类的定义: public class HashMap< ...
- js中取整数的方法
1.取整的方法 Math.floor( ) Math 对象的方法--取比当前数值小的最大整数(下取整). Math.ceil( ) Math对象的方法--取比当前数值大的最小整数(上取整). Math ...
- SVN的三种merge方式【转】
SVN的merge操作是为了保证主干(trunk)和分支(branch)同步,merge方式有: 1.Merge a range of revisions(合并一个范围的版本) 2.Reintegra ...