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 ...
随机推荐
- Python机器学习算法 — 支持向量机(SVM)
SVM--简介 <α∗j<C,可得: 构造决策函数: 5.求最优解 要求解的最优化问题如下: 考虑使用序列最小最优化算法(SMO,se ...
- [App Store Connect帮助]六、测试 Beta 版本(4.1) 管理 Beta 版构建版本:为构建版本添加测试员
在“TestFlight”部分中,您可以查看您所有 App 版本的构建版本,并深入查看构建版本的详细信息.您也可以为某个构建版本添加群组或独立测试员. 必要职能:“帐户持有人”职能.“管理”职能或“A ...
- Extjs6 经典版 combo下拉框数据的使用及动态传参
Extjs的下拉框,在点击的时候会请求一次数据,我们可不可以在点击前就请求好数据,让用户体验更好呢?答案当然是肯定的.如果是公用的下拉框还可以传入不同参数请求不同数据. 第一步: 进入页面前首先加载s ...
- ASP.NET MVC5 之 客户端实现文件的下载
MVC 实现下载功能主要借助于 File 属性: //下载文件接口 public ActionResult GetTrackTempIsc(ICSModels icsModels) { bool fl ...
- 51nod1298 圆与三角形
1298 圆与三角形 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出圆的圆心和半径,以及三角形的三个顶点,问圆同三 ...
- 莫队算法/二分查找 FZU 2072 Count
题目传送门 题意:问区间内x的出现的次数分析:莫队算法:用一个cnt记录x的次数就可以了.还有二分查找的方法 代码: #include <cstdio> #include <algo ...
- {Python}安装第三方包(setup.py)
在github上下载了records文件到本地. 解压文件 cmd切换到文件setup.py的目录下 先执行 python setup.py build 再执行python setup.py inst ...
- hdu5122 K.Bro Sorting
思路: 模拟. 实现: #include <iostream> #include <cstdio> using namespace std; ], n, t; int main ...
- FCC 基础JavaScript 练习2
1. 引号不是字符串中唯一的可以被转义字符.下面是常见的转义序列列表: \' 单引号 \" 双引号 \\ 反斜杠符 \n 换行符 \r 回车符 \t 制表符 \b 退格符 \f 换页符 ...
- C#常见问题总结(三)
11.sql比access好在哪里,为什么都用sql 解决方法: 数据量大,可以在服务器端,access一般在单机的时候用 12.c#基础视频教程有吗 解决方法: 零基础学C#这本书带全套C#基础视频 ...