传送门: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. BestCoder Round #92 1002 Count the Sheep —— 枚举+技巧

    题目链接:http://bestcoder.hdu.edu.cn/contests/contest_showproblem.php?cid=748&pid=1002 题解: 做题的时候只是想到 ...

  2. 利用javascript动态创建表格

    //说明:实现功能.原理上文相同.不过这次是利用已有的简单的方法创建行和列,并实现内容行鼠标移入变色功能! 效果图: /*两个方法 1.  trNode  table.insertRow(-1)    ...

  3. Objective-C学习之解析XML

    通过soap请求webservice时,返回的数据是XML类型,有时候也需要解析本地的xml数据等,苹果自带类NSXMLParser解析xml还是很方便的,简单轻便 本文以解析本地XML为例,网络获取 ...

  4. [SPOJ1557] Can you answer these queries II

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2482 [算法] 线段树维护历史最值 时间复杂度 : O(NlogN) [代码] #i ...

  5. DBCPTool

    dbcp读取配置文件的方式: 1. 导入3个包:commons-dbcp-...  .jar(数据源) commons-collections-.....jar(集合) commons-pool... ...

  6. centos7 安装 python3.5

    centos7 安装 python3.5 一. python虚拟环境virtualenv VirtualEnv用于在一台机器上创建多个独立的python运行环境,VirtualEnvWrapper为前 ...

  7. c语言中#和##的用法

    一.一般用法 我们使用#把宏参数变为一个字符串,用##把两个宏参数贴合在一起. 用法: #include<cstdio> #include<climits> using nam ...

  8. 利用JavaScript选择GridView行

    本篇技巧和诀窍记录的是:利用JavaScript选择GridView行. 当我们想在GridView中添加删除.选择功能时,我们通常的做法是利用模板功能在每行添加一个按钮控件或者超链接按钮控件,单击按 ...

  9. SqlServer2012——Select,分组,排序、插入

    1.select 简单语句 --select语句 * --select子句 * AS result --select子句,可以将结果保存在result中 ~~~~~~~~~~~~~~~~~~~~~~~ ...

  10. SQL——基础概念

    服务器登录名:指有权限登录到某服务器的用户:如sa 服务器角色:指一组固定的服务器用户,默认有9组: 登录名一定属于某些角色,默认为public 服务器角色不容许更改 登录后也不一定有权限操作数据库 ...