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. 【总结】关于YUV-RGB格式转换的一些个人理解

    这段时间一直在研究YUV的格式问题例如YUV422.YUV420,在网上搜索了很多这方面的资料,发现很多资料讲的东西是重复的,没有比较深入的讲解,所以看了之后印象不是很深,过了一段时间之后又对它们有了 ...

  2. Git简单图文教程

    环境: Windows [版本 10.0.15063]64位 Git-2.14.1 64位[下载] TortoiseGit-2.5.0.0 64位[下载],这是一个Git 客户端,外号"乌龟 ...

  3. 第2次作业:Wechat创作史

    Wechat创作史   比尔盖茨曾经说过一句话:21世纪要么电子商务,要么无商可务. 2.1 介绍产品相关信息 -the information about Wechat 你选择的产品是? 选择微信作 ...

  4. org.hibernate.hibernate.connection.release_mode

    org.hibernate.connection包的主要封装了通过JDBC来连接数据库的操作,用户可以以数据源的方式,或者通过特定数据库驱动的方式,甚至是自己定义连接类的方式来完成数据库的连接操作,包 ...

  5. Spring-Data-JPA整合MySQL和配置

    一.简介 (1).MySQL是一个关系型数据库系统,是如今互联网公司最常用的数据库和最广泛的数据库.为服务端数据库,能承受高并发的访问量. (2).Spring-Data-Jpa是在JPA规范下提供的 ...

  6. C# 大数组赋值给小数组,小数组赋值给大数组

    ]; ]; " }; arraymax = arraystr;//变成和arraystr一样 arraymin = arraystr;//变成和arraystr一样

  7. PHP常见排序算法

    $a = [1, 3, 5, 2, 4, 6, 12, 60, 45, 10, 32];$len = count($a);$num=0;/* * 冒泡排序 * 原理:不停的对相邻两个数进行比较,直到最 ...

  8. SpringBoot的重要特性

    一.Web特性 Spring Boot 提供了spring-boot-starter-web来为Web开发予以支持,spring-boot-starter-web为我们提供了嵌入的Tomcat以及Sp ...

  9. Django REST framework+Vue 打造生鲜超市(四)

    五.商品列表页 5.1.django的view实现商品列表页 (1)goods/view_base.py 在goods文件夹下面新建view_base.py,为了区分django和django res ...

  10. Django 基于session认证 小作业

    基于session认证  相亲小作业 用户登录 如果男用户登录,显示女生列表 如果女用户登录,显示男生列表 """s4day74 URL Configuration Th ...