传送门: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. Appium基础——需要知道的

      Appium使用平台厂商提供的自动化框架: 1.ios 苹果的UIAutomation 2.android google的UIAutomator Appium底层使用厂商提供的自动化框架,就不需要 ...

  2. suishou

    sageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn you ...

  3. PHP截取中英文混合字符

    <?php //////////////////////////////////////////////////////////////////// // PHP截取中英文及标点符号混合的字符串 ...

  4. Linux档案属性

    输入命令:ls -al 档案类型权限: 第一個字元代表这个档案是『目录.档案或链接档等等』: 当为[ d ]则是目录: 当为[ - ]则是目录: 若是[ l ]则表示为链接档(link file): ...

  5. 在SQL SERVER 2008中通过已有的数据库生成建库脚本

  6. 三剑客之awk数组实战

    shell数组for循环 第一种: #!/bin/sh array=(1 2 3) for i in ${array[*]}  do    echo $i done   第二种: #!/bin/sh ...

  7. 深入理解java虚拟机---->java内存区域与内存溢出异常

    2. java内存区域于内存溢出异常 2.1 概述: 对于C/C++而言,内存管理具有最高的权利,既拥有每一个对象的“所有权”,又担负着每一个对象生命开始到结束的维护责任. 对于java而言,则把内存 ...

  8. 爬虫库之BeautifulSoup学习(三)

    遍历文档树: 1.查找子节点 .contents tag的.content属性可以将tag的子节点以列表的方式输出. print soup.body.contents print type(soup. ...

  9. HDOJ-2058

    The sum problem Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  10. Understand中的Graphical Views使用

    Graphical Views 用于浏览代码结构. 下面以dso为例 1.Butterfly 显示include关系.例: 2.Declaration 文件中的类.例: 3.UML Class Dia ...