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 ...
随机推荐
- MySQL 启动服务和登陆参数
启动MySQL服务:net start mysql; 停止MySQL服务:net stop mysql; 参数 描述 -D,--database=name 打开指定数据库 --delimiter=na ...
- P3297 [SDOI2013]逃考
传送门 完全看不出这思路是怎么来的-- 首先对于两个亲戚,他们监视范围的边界是他们连线的中垂线.那么对于一个亲戚来说它能监视的范围就是所有的中垂线形成的半平面交 然后如果某两个亲戚的监视范围有公共边, ...
- lodop打印图片
LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM')); //LODOP. ...
- C#封装访问修饰符
C# 封装 封装 被定义为"把一个或多个项目封闭在一个物理的或者逻辑的包中".在面向对象程序设计方法论中,封装是为了防止对实现细节的访问. 抽象和封装是面向对象程序设计的相关特性. ...
- ListView(4)取消GridView/ListView item被点击时的效果
方法一,在代码中设置 gridView.setSelector(new ColorDrawable(Color.TRANSPARENT)); listView.setSelector(new Colo ...
- layer父页获取弹出层输入框里面的值
主要是因为修改功能,原来页面填写数据如图 改为 其中点击填写明细弹出框 填写完毕后点击确认返回,同事这里因为她是存的多表,所以点击确认就直接保存数据了,改的这个功能原本保存是整体保存,我就不想改原来的 ...
- Http请求1
package Test; import java.io.IOException; import java.io.InputStreamReader; import java.net.URISynta ...
- [转] Android利用Fiddler进行网络数据抓包
主要介绍Android及IPhone手机上如何利用Fiddler进行网络数据抓包,比如我们想抓某个应用(微博.微信.墨迹天气)的网络通信请求就可以利用这个方法. Mac 下请使用 Charles 代替 ...
- [转]MapReduce浅析
本文转自http://edisonchou.cnblogs.com/ 一.什么是MapReduce MapReduce是Google的一项重要技术,它首先是一个编程模型,用以进行大数据量的计算.对于大 ...
- taskctl命令行类(sh、exe、python新增scp)插件升级扩展
转载自: http://www.taskctl.com/forum/detail_129.html 上次写了一个帖子 TASKCTL中不使用代理,通过ssh免密连接执行远程脚本配置(SSH插件扩展)h ...