[WC 2010]重建计划
Description

Input
第一行包含一个正整数N,表示X国的城市个数. 第二行包含两个正整数L和U,表示政策要求的第一期重建方案中修建道路数的上下限 接下来的N-1行描述重建小组的原有方案,每行三个正整数Ai,Bi,Vi分别表示道路(Ai,Bi),其价值为Vi 其中城市由1..N进行标号
Output
输出最大平均估值,保留三位小数
Sample Input
2 3
1 2 1
1 3 2
1 4 3
Sample Output
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]重建计划的更多相关文章
- BZOJ1758: [Wc2010]重建计划
题解: 这题我居然做了一星期?... 平均值的极值其实也可以算是一种分数规划,只不过分母上b[i]=1 然后我们就可以二分这个值.类似与 HNOI最小圈 如果没有 链的长度的限制的话,我们直接两遍df ...
- bzoj1758Wc10重建计划——solution
1758: [Wc2010]重建计划 Time Limit: 40 Sec Memory Limit: 162 MBSubmit: 4707 Solved: 1200[Submit][Status ...
- BZOJ 1758 【WC2010】 重建计划
题目链接:重建计划 这道题现在已经成为一道板子题了…… 这是个非常显然的0-1分数规划,可以二分答案之后树分治判定一下.注意树分治的时候如果使用单调队列,需要把所有儿子预先按最大深度排好序,否则会被扫 ...
- 洛谷 P4292 [WC2010]重建计划 解题报告
P4292 [WC2010]重建计划 题目描述 \(X\)国遭受了地震的重创, 导致全国的交通近乎瘫痪,重建家园的计划迫在眉睫.\(X\)国由\(N\)个城市组成, 重建小组提出,仅需建立\(N-1\ ...
- [WC2010]重建计划 长链剖分
[WC2010]重建计划 LG传送门 又一道长链剖分好题. 这题写点分治的人应该比较多吧,但是我太菜了,只会长链剖分. 如果你还不会长链剖分的基本操作,可以看看我的长链剖分总结. 首先一看求平均值最大 ...
- 【BZOJ1758】【WC2010】重建计划(点分治,单调队列)
[BZOJ1758][WC2010]重建计划(点分治,单调队列) 题面 BZOJ 洛谷 Description Input 第一行包含一个正整数N,表示X国的城市个数. 第二行包含两个正整数L和U,表 ...
- 「WC2010」重建计划(长链剖分/点分治)
「WC2010」重建计划(长链剖分/点分治) 题目描述 有一棵大小为 \(n\) 的树,给定 \(L, R\) ,要求找到一条长度在 \([L, R]\) 的路径,并且路径上边权的平均值最大 \(1 ...
- [bzoj 1758] 重建计划
bzoj 1758 重建计划 题意: 给定一棵有边权的树和两个数 \(L, R (L\leq R)\),求一条简单路径,使得这条路径经过的边数在 \(L, R\) 之间且路径经过的边的边权的平均值最大 ...
- bzoj 1758 [Wc2010]重建计划 分数规划+树分治单调队列check
[Wc2010]重建计划 Time Limit: 40 Sec Memory Limit: 162 MBSubmit: 4345 Solved: 1054[Submit][Status][Disc ...
随机推荐
- MySQL数据库操作类(PHP实现,支持连贯操作)
<?php /** * Author: suvan * CreateTime: 2018/2/27 * description: 数据库操作类(仅对接MySQL数据库,主要利用MySQLi函数) ...
- 项目Alpha冲刺Day6
一.会议照片 二.项目进展 1.今日安排 熟悉后台框架并编写.继续搭建前台框架模版.熟悉前端框架开发流程.完成前端热部署配置.完成部分后台用户信息相关接口.解决后台jdk1.8日期在框架中的使用. 2 ...
- java关于for循环。
众所周知,JAVA中for循环的基本格式为: for(初始化表达式:布尔表达式:循环后更新表达式){循环体} 举个例子来说可以写成 (1)for (int x=1;x<10;x++){ Syst ...
- OpenCASCADE Trihedron Law
OpenCASCADE Trihedron Law eryar@163.com Abstract. In differential geometry the Frenet-Serret formula ...
- c#动态加载卸载DLL
前段时间工作的时候遇到一个问题.就是需要每次启动程序的时候动态替换掉某个dll,所以就百度了这方面的资料.这次记录下来让自己以后可以看. 根据自己的理解,动态卸载dll需要有以下条件: 1:dll在加 ...
- Linq 对象的比较 Contains,Max
IList<Student> studentList = new List<Student>() { new Student() { StudentID = 1, Studen ...
- PHP模式设计之单例模式、工厂模式、注册树模式、适配器模式、观察者模式
php模式设计之单例模式 什么是单例模式? 单例模式是指在整个应用中只有一个实例对象的设计模式 为什么要用单例模式? php经常要链接数据库,如果在一个项目中频繁建立连接数据库,会造成服务器资源的很大 ...
- springboot字符集乱码
入门扫盲:https://www.2cto.com/database/201701/584442.html 1.修改springweb类bug 2.数据库连接配置 3.数据库字符集 https://w ...
- HTTP协议的消息头:Content-Type和Accept的作用
一.背景知识 1.概述 Http报头分为通用报头,请求报头,响应报头和实体报头. 请求方的http报头结构:通用报头|请求报头|实体报头 响应方的http报头结构:通用报头|响应报头|实体报头 Acc ...
- ELK学习总结(1-1)ELK是什么
1.elk 是什么 ? Elastic Stack(旧称ELK Stack),是一种能够从任意数据源抽取数据,并实时对数据进行搜索.分析和可视化展现的数据分析框架.(hadoop同一个开发人员) ja ...