Title: http://www.lydsy.com/JudgeOnline/problem.php?id=1758
01 Score Planning, so we have two points for each center of gravity. The problem is then converted to σw[e]-mid>=0, the Dep,dis of a subtrees tree maintenance point, and stored with queue Q. Mx[i] indicates that the current DEP is the maximum weight of I, maintains a monotonic queue DQ, maintains the current qualifying MX, and when we sweep forward from the tail of Q, its DEP is decremented, using this nature to maintain the monotone queue, and finally update the MX again. Look at the code, tat.
Code:
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <queue>
#include <set>
#include <cmath>
#define REP (i,l,r) for (int i=l;i<=r;i++)
#define DOWN (I,L,R) for (int i=l;i>=r;i--)
#define CLR (x, y) memset (x,y,sizeof (×))
#define MAXN 209000
#define INF Int (1E9)
#define MM 1000000007
#define ESP 1e-6
using namespace Std;
#define LL Long Long
struct Data{int obj,pre; double C;
}E[MAXN*2];
int HEAD[MAXN],S[MAXN],Q[MAXN],DQ[MAXN],DEP[MAXN],FA[MAXN],VIS[MAXN];
Double ANS,LIM,DIS[MAXN],MX[MAXN];
int n,m,tot,sum,mn,rt,l,u;
int read () {
int x=0,f=1; Char Ch=getchar ();
while (!isdigit (CH)) {if (ch== '-') f=-1; Ch=getchar ();}
while (IsDigit (CH)) x=x*10+ch-' 0 ', Ch=getchar ();
return x*f;
}
void Insert (int x,int y,double z) {
E[++tot].obj=y; E[tot].c=z; E[TOT].PRE=HEAD[X]; Head[x]=tot;
}
void Dfs (int u,int fa) {
S[u]=1; int mx=0;
for (int j=head[u];j;j=e[j].pre) {
int v=e[j].obj;
if (V!=fa&&!vis[v]) {
DFS (V,U);
S[U]+=S[V];
Mx=max (Mx,s[v]);
}
}
Mx=max (MX,SUM-MX);
if (mx<mn) mn=mx,rt=u;
}
BOOL Go (int u,double mid) {
int up=0;
for (int j=head[u];j;j=e[j].pre) {
int v=e[j].obj;
if (Vis[v]) continue;
Dep[v]=1; Dis[v]=e[j].c-mid; Fa[v]=u;
int l=0,r=1; Q[1]=v;
while (L<r) {
int now=q[++l];
for (int k=head[now];k;k=e[k].pre) {
int v=e[k].obj;
if (V!=fa[now]&&!vis[v]) {
Fa[v]=now; dep[v]=dep[now]+1; Dis[v]=dis[now]+e[k].c-mid;
Q[++r]=v;
}
}
}
int tail=r; l=1; r=0; int now=up;
Rep (I,1,tail) {
while (dep[q[i]]+now>=l&&now>=0) {
while (L<=r&&mx[now]>mx[dq[r]]) r--;
Dq[++r]=now;
now--;
}
while (L<=r&&dep[q[i]]+dq[l]>u) l++;
if (l<=r&&dis[q[i]]+mx[dq[l]]>=0) return 1;
}
Rep (I,up+1,dep[q[tail]]) Mx[i]=-inf;
Rep (I,1,tail) {
int Now=dep[q[i]];
Mx[now]=max (Mx[now],dis[q[i]);
}
Up=max (Up,dep[q[tail]);
}
return 0;
}
void Jud (int u) {
Double L=ans,r=lim;
while (r-l>=0.0001) {
Double mid= (l+r)/2;
if (Go (u,mid)) L=mid;
else R=mid;
}
Ans=l;
}
void solve (int u) {
Mn=inf;
DFS (u,0);
U=rt;
Jud (U);
Vis[u]=1;
for (int j=head[u];j;j=e[j].pre) {
int v=e[j].obj;
if (!vis[v]) {
SUM=S[V];
if (sum>l) solve (v);
}
}
}
int main () {
N=read ();
L=read (); U=read ();
int x, y; Double Z;
Rep (i,1,n-1) {
X=read (); Y=read (); scanf ("%lf", &z);
Insert (x, y, z);
Insert (Y,X,Z);
Lim=max (LIM,Z);
}
Sum=n;
Solve (1);
printf ("%.3lf\n", ans);
return 0;
}
BZOJ1758: [Wc2010] Reconstruction Plan (01 score Plan + Point division + monotone queue)