传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2809

保存可并堆模版代码。

#include <cstdio>
#include <cstring>
#include <algorithm> const int maxn = 100005, maxm = 1000000005; int n, m, fa[maxn], salary[maxn], lead[maxn];
int key[maxn], left[maxn], right[maxn], npl[maxn], cnt, siz[maxn];
int head[maxn], to[maxn], next[maxn], lb;
long long s[maxn], ans; inline void ist(int aa, int ss) {
to[lb] = ss;
next[lb] = head[aa];
head[aa] = lb;
++lb;
}
int merge(int A, int B) {
if (!A) {
return B;
}
if (!B) {
return A;
}
if (key[B] > key[A]) {
std::swap(A, B);
}
right[A] = merge(right[A], B);
if (npl[right[A]] > npl[left[A]]) {
std::swap(left[A], right[A]);
}
npl[A] = npl[right[A]] + 1;
s[A] = s[left[A]] + s[right[A]] + key[A];
siz[A] = siz[left[A]] + siz[right[A]] + 1;
return A;
}
int dfs(int r) {
int rt = ++cnt, tr = -666;
key[rt] = salary[r];
s[rt] = salary[r];
siz[rt] = 1;
for (int j = head[r]; j != -1; j = next[j]) {
tr = dfs(to[j]);
rt = merge(rt, tr);
}
while (s[rt] > m) {
rt = merge(left[rt], right[rt]);
}
ans = std::max(ans, (long long)lead[r] * (long long)siz[rt]);
return rt;
} int main(void) {
//freopen("in.txt", "r", stdin);
memset(head, -1, sizeof head);
memset(next, -1, sizeof next);
npl[0] = -1;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d%d%d", fa + i, salary + i, lead + i);
ist(fa[i], i);
} dfs(1);
printf("%lld\n", ans);
return 0;
}

  

bzoj2806 [Apio2012]dispatching【可并堆】的更多相关文章

  1. 【BZOJ2809】[Apio2012]dispatching 可并堆

    [BZOJ2809][Apio2012]dispatching Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 M ...

  2. bzoj 2809: [Apio2012]dispatching -- 可并堆

    2809: [Apio2012]dispatching Time Limit: 10 Sec  Memory Limit: 128 MB Description 在一个忍者的帮派里,一些忍者们被选中派 ...

  3. BZOJ2809 [Apio2012]dispatching 可并堆

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ2809 题意概括 n个点组成一棵树,每个点都有一个领导力和费用,可以让一个点当领导,然后在这个点的子 ...

  4. BZOJ 2809 [Apio2012]dispatching(斜堆+树形DP)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2809 [题目大意] 给出一棵树,求出每个点有个权值,和一个乘算值,请选取一棵子树, 并 ...

  5. 2809: [Apio2012]dispatching 可并堆 左偏树

    https://www.lydsy.com/JudgeOnline/problem.php?id=2809 板子题wa了一下因为输出ans没有lld #include<iostream> ...

  6. 【bzoj2809】[Apio2012]dispatching 左偏树

    2016-05-31  15:56:57 题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2809 直观的思想是当领导力确定时,尽量选择薪水少的- ...

  7. [Apio2012]dispatching

    [Apio2012]dispatching 时间限制: 1 Sec  内存限制: 128 MB 题目描述 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一 ...

  8. bzoj2809 [Apio2012]dispatching(左偏树)

    [Apio2012]dispatching Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 M ...

  9. [Apio2012]dispatching 主席树做法

    bzoj 2809: [Apio2012]dispatching http://www.lydsy.com/JudgeOnline/problem.php?id=2809 Description 在一 ...

随机推荐

  1. Ubuntu下codeblocks编译器程序执行对话框内能进行粘贴编辑操作的指令

    如这个:  gnome-terminal  -t $TITLE -x

  2. Gym - 100187A A - Potion of Immortality —— 贪心

    题目链接:http://codeforces.com/gym/100187/problem/A 题解: 光题意就想了很久:在最坏情况下的最小兔子数.其实就是至少用几只兔子就一定能找出仙药(答案存在的话 ...

  3. this.triggerEvent()用法

    在对组件进行封装时 在当前页面想要获取组件中的某一状态,需要使用到this.triggerEvent(' ',{},{}),第一个参数是自定义事件名称,这个名称是在页面调用组件时bind的名称,第二个 ...

  4. hdu-5596 GTW likes gt(模拟+优先队列)

    题目链接: GTW likes gt  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 131072/131072 K (Java/Othe ...

  5. BZOJ_4010_[HNOI2015]菜肴制作_拓扑排序+贪心

    BZOJ_4010_[HNOI2015]菜肴制作_拓扑排序+贪心 Description 知名美食家小 A被邀请至ATM 大酒店,为其品评菜肴. ATM 酒店为小 A 准备了 N 道菜肴,酒店按照为菜 ...

  6. bzoj1799同类分布——数位DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1799 数位DP. 1.循环方法 预处理出每个位数上,和为某个数,模某个数余某个数的所有情况: ...

  7. HDU1203(01背包变形)

    I NEED A OFFER! Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   D ...

  8. 1.Win7中判断当前端口是否被占用

    以Win7为例,可以用如下方法找出某个端口是否被其他进程占用:netstat -aon|findstr "8081" 发现8081端口被PID为5900的进程占用, tasklis ...

  9. Eclipse -- 自动补齐设置和其他用法

    1:自动补齐设置:最简单的修改方式是:Windows——>Preferences——>Java-->Editor-->Content Asist,在Auto activatio ...

  10. yzm10铺瓷砖 一只小蜜蜂 ycb与取款机

    yzm10铺瓷砖 一天yzm10接到任务,要求用2×1大小的瓷砖,来铺2×4的地面,地面需要恰好被铺满.这对yzm10来说太容易了,于是他马上设计出了5种不同的铺法(旋转情况算不同种,如图示2.4). ...