Description

Input

第一行包含一个正整数N,表示X国的城市个数. 第二行包含两个正整数L和U,表示政策要求的第一期重建方案中修建道路数的上下限 接下来的N-1行描述重建小组的原有方案,每行三个正整数Ai,Bi,Vi分别表示道路(Ai,Bi),其价值为Vi 其中城市由1..N进行标号

Output

输出最大平均估值,保留三位小数

Sample Input

4
2 3
1 2 1
1 3 2
1 4 3

Sample Output

2.500

HINT

N<=100000,1<=L<=U<=N-1,Vi<=1000000

题解

本机实测是可以 $A$ 的,但爆炸 $oj$ 的老爷机实在不可恭维,并且还多加了一组更为毒瘤的数据...

加了所有的常数优化都过不了,气愤的不想写题解,直接丢链接。

->题解在这里<-

 //It is made by Awson on 2018.1.5
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define RE register
#define lowbit(x) ((x)&(-(x)))
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
using namespace std;
const int N = ;
const int INF = ~0u>>;
const double eps = 4e-;
void read(int &x) {
char ch; x = ;
ch = getchar(); while (ch < '' || ch > '') ch = getchar();
while (ch >= '' && ch <= '') x = (x<<)+(x<<)+ch-, ch = getchar();
} int n, L, U, a, b, c;
struct tt {
int to, next;
double cost, c;
}edge[(N<<)+];
int path[N+], top;
int root[N+];
void add(int u, int v, double c) {
edge[++top].to = v;
edge[top].cost = edge[top].c = c;
edge[top].next = path[u];
path[u] = top;
} namespace PRE {
int size[N+], mx[N+], minsize, rt, vis[N+], tot;
void get_root(int o, int pa, int fa) {
mx[o] = Max(mx[o], size[pa]-size[o]);
if (mx[o] < minsize) minsize = mx[o], rt = o;
for (RE int i = path[o]; i; i = edge[i].next)
if (edge[i].to != fa && !vis[edge[i].to]) get_root(edge[i].to, pa, o);
}
void get_size(int o, int fa) {
size[o] = , mx[o] = ;
for (RE int i = path[o]; i; i = edge[i].next)
if (edge[i].to != fa && !vis[edge[i].to]) {
get_size(edge[i].to, o);
size[o] += size[edge[i].to];
if (size[edge[i].to] > mx[o]) mx[o] = size[edge[i].to];
}
}
void work(int o) {
minsize = INF;
get_size(o, ), get_root(o, o, );
root[++tot] = rt, vis[rt] = ;
for (RE int i = path[rt]; i; i = edge[i].next)
if (!vis[edge[i].to]) work(edge[i].to);
}
void main() {work(); }
} double mx[N+], dist[N+];
int q[N+], vis[N+], dep[N+], dq[N+], fa[N+]; bool cal(int o) {
int maxdep = ;
for (RE int I = path[o]; I; I = edge[I].next)
if (!vis[edge[I].to]) {
int head = , tail = ; q[tail] = edge[I].to, dep[q[]] = , dist[q[]] = edge[I].cost, fa[q[]] = o, ++tail;
while (head < tail) {
int now = q[head]; ++head;
for (RE int i = path[now]; i; i = edge[i].next)
if (fa[now] != edge[i].to && !vis[edge[i].to]) {
q[tail] = edge[i].to, ++tail;
dep[edge[i].to] = dep[now]+;
dist[edge[i].to] = dist[now]+edge[i].cost;
fa[edge[i].to] = now;
}
}
int head1 = , tail1 = , now = maxdep;
for (RE int i = ; i < tail; ++i) {
int x = q[i];
while (dep[x]+now >= L && now >= ) {
while (head1 < tail1 && mx[dq[tail1-]] < mx[now]) --tail1;
dq[tail1] = now; ++tail1, --now;
}
while (head1 < tail1 && dq[head1]+dep[x] > U) ++head1;
if (head1 < tail1 && dist[x]+mx[dq[head1]] >= ) return true;
}
maxdep = Max(maxdep, dep[q[tail-]]);
for (RE int i = ; i < tail; ++i) {
fa[q[i]] = ; if (mx[dep[q[i]]] < dist[q[i]]) mx[dep[q[i]]] = dist[q[i]];
}
}
for (RE int i = ; i <= maxdep; i++) mx[i] = -INF;
return false;
}
bool solve(int o, int &num) {
vis[o] = ;
if (cal(o)) return true;
for (RE int i = path[o]; i ;i = edge[i].next)
if (!vis[edge[i].to]) {
++num; if (solve(root[num], num)) return true;
}
return false;
}
void pre(double key) {
for (RE int i = ; i <= n; ++i) {
edge[i<<].cost = edge[i<<].c-key, edge[(i<<)-].cost = edge[(i<<)-].c-key;
vis[i] = , mx[i] = -INF;
}
}
void work() {
read(n), read(L), read(U);
double L = , R = ;
for (RE int i = ; i < n; ++i) {
read(a), read(b), read(c);
add(a, b, c), add(b, a, c); if (R < c) R = c;
}
PRE::main();
while (R-L > eps) {
double mid = (L+R)/.; pre(mid);
int tot = ;
if (solve(root[], tot)) L = mid;
else R = mid;
}
printf("%.3lf\n", (L+R)/.);
}
int main() {
work();
return ;
}

[WC 2010]重建计划的更多相关文章

  1. BZOJ1758: [Wc2010]重建计划

    题解: 这题我居然做了一星期?... 平均值的极值其实也可以算是一种分数规划,只不过分母上b[i]=1 然后我们就可以二分这个值.类似与 HNOI最小圈 如果没有 链的长度的限制的话,我们直接两遍df ...

  2. bzoj1758Wc10重建计划——solution

    1758: [Wc2010]重建计划 Time Limit: 40 Sec  Memory Limit: 162 MBSubmit: 4707  Solved: 1200[Submit][Status ...

  3. BZOJ 1758 【WC2010】 重建计划

    题目链接:重建计划 这道题现在已经成为一道板子题了…… 这是个非常显然的0-1分数规划,可以二分答案之后树分治判定一下.注意树分治的时候如果使用单调队列,需要把所有儿子预先按最大深度排好序,否则会被扫 ...

  4. 洛谷 P4292 [WC2010]重建计划 解题报告

    P4292 [WC2010]重建计划 题目描述 \(X\)国遭受了地震的重创, 导致全国的交通近乎瘫痪,重建家园的计划迫在眉睫.\(X\)国由\(N\)个城市组成, 重建小组提出,仅需建立\(N-1\ ...

  5. [WC2010]重建计划 长链剖分

    [WC2010]重建计划 LG传送门 又一道长链剖分好题. 这题写点分治的人应该比较多吧,但是我太菜了,只会长链剖分. 如果你还不会长链剖分的基本操作,可以看看我的长链剖分总结. 首先一看求平均值最大 ...

  6. 【BZOJ1758】【WC2010】重建计划(点分治,单调队列)

    [BZOJ1758][WC2010]重建计划(点分治,单调队列) 题面 BZOJ 洛谷 Description Input 第一行包含一个正整数N,表示X国的城市个数. 第二行包含两个正整数L和U,表 ...

  7. 「WC2010」重建计划(长链剖分/点分治)

    「WC2010」重建计划(长链剖分/点分治) 题目描述 有一棵大小为 \(n\) 的树,给定 \(L, R\) ,要求找到一条长度在 \([L, R]\) 的路径,并且路径上边权的平均值最大 \(1 ...

  8. [bzoj 1758] 重建计划

    bzoj 1758 重建计划 题意: 给定一棵有边权的树和两个数 \(L, R (L\leq R)\),求一条简单路径,使得这条路径经过的边数在 \(L, R\) 之间且路径经过的边的边权的平均值最大 ...

  9. bzoj 1758 [Wc2010]重建计划 分数规划+树分治单调队列check

    [Wc2010]重建计划 Time Limit: 40 Sec  Memory Limit: 162 MBSubmit: 4345  Solved: 1054[Submit][Status][Disc ...

随机推荐

  1. 百词斩APP分析

    一.调研 1.第一次上手   第一次使用,可以使用微信和qq登录感觉挺不错的不然又要注册有点麻烦,在功能上,用户可以针对自身选择不同水平的英语背单词,然后有多钟方式对自己的听力和单词翻译进行提升.在u ...

  2. 关于使用栈将一般运算式翻译为后缀表达式并实现三级运算的方法及实例(cpp版)

    #include <iostream> #include <stack> #include <vector> #include <string> #de ...

  3. 关于collectionView和tableView的两种cell的出列方法的区别

    相信好多人一定会对collectionView和tableView的两种cell出列方法有所疑问,下面以UICollection为例子进行举例说明 假设我们已经创建了一个collectionView, ...

  4. OO第一次阶段性总结

    经过三次作业的历练之后终于来到了写博客这一周.回顾开学来的这一个月,令我印象最深刻也是最累的一门课就是OO了.虽然上学期学过一部分Java,但这学期开学就来的OO作业还是让我在第二周就开始熬夜了.不过 ...

  5. EasyUI 主布局整合。

    博文学习地址:http://www.cnblogs.com/xishuai/p/3620327.html html: <%@ Page Language="C#" AutoE ...

  6. [JCIP笔记] (二)当我们谈线程安全时,我们在谈论什么

    总听组里几个大神说起线程安全问题.本来对"线程安全"这个定义拿捏得就不是很准,更令人困惑的是,大神们用这个词指代的对象不仅抽象而且千变万化.比如,我们的架构师昨天说: " ...

  7. 韩顺平dedecms讲解上课记录

    感谢韩顺平: 如何打开php的gd库,通过php设置->php扩展-->phpdb库;打上勾就行: dede存在四张十分重要的表,channeltype,模型表最原始的发源arctype: ...

  8. AngularJS1.X学习笔记8-自定义指令(上)

    AngulaJS的指令是一种非常强大的特性,一个ng-repeat就能让我们非常方便的展示一个数据列表,指令相当于是一个组件,为我们将一些东西封装起来了,提供了复用的可能性.个人认为自定义指令还是比较 ...

  9. Docker学习笔记 - Docker Compose

    一.概念 Docker Compose 用于定义运行使用多个容器的应用,可以一条命令启动应用(多个容器). 使用Docker Compose 的步骤: 定义容器 Dockerfile 定义应用的各个服 ...

  10. Linux实战案例(3)创建和删除用户

    建用户: adduser phpq                            //新建phpq用户passwd phpq                            //给php ...