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. Rails + React +antd + Redux环境搭建

    前提条件:node和ruby on rails必须已经安装好(相关安装流程不再此处介绍) 1.nvm.node 2.npm or yarn装一个就好 3.rvm.ruby on rails 4.for ...

  2. 敏捷冲刺每日报告--day2

      1 团队介绍 团队组成: PM:齐爽爽(258) 小组成员:马帅(248),何健(267),蔡凯峰(285)  Git链接:https://github.com/WHUSE2017/C-team ...

  3. 201621123057 《Java程序设计》第6周学习总结

    1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图或相关笔记,对面向对象思想进行一个总结. 注1:关键词与内容不求多,但概念之间的联系要清晰 ...

  4. Oracle查询用户权限

    Oracle查询用户权限 -- 确定角色的权限select * from role_tab_privs ;              包含了授予角色的对象权限select * from role_ro ...

  5. Java中三种比较常见的数组排序

    我们学习数组比较常用的数组排序算法不是为了在工作中使用(这三个算法性能不高),而是为了练习for循环和数组.因为在工作中Java API提供了现成的优化的排序方法,效率很高,以后工作中直接使用即可 . ...

  6. Linux下关闭Tomcat残留线程

    ps -ef | grep tomcat kill -9 {pid}

  7. JDBC操作数据库的三种方式比较

    JDBC(java Database Connectivity)java数据库连接,是一种用于执行上sql语句的javaAPI,可以为多种关系型数据库提供统一访问接口.我们项目中经常用到的MySQL. ...

  8. jquery基础总结 -- 转载

    jquery的each里面return的使用 在使用jquery的each方法时, return false相当于break,是跳出each循环,return true相当于continue,是继续循 ...

  9. 职场选择之大公司 VS 小公司

    其实这是个非常难回答的问题,很多职场新人都会有类似的顾虑和疑问. 这个问题就好比业界比较容易引起争议的编程语言哪个是最好的一样.大公司还是小公司里面发展,只有身处其中才能体会,如人饮水,冷暖自知. 笔 ...

  10. JAVA_SE基础——48.多态

    面向对象程序设计的三个特点是封装.继承和多态.前面已经学习了前两个特点.本章节将介绍多态性. 多态:一个对象具备多种形态.(父类的引用类型变量指向了子类的对象)或者是接口 的引用类型变量指向了接口实现 ...