bzoj2806 [Apio2012]dispatching【可并堆】
传送门: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【可并堆】的更多相关文章
- 【BZOJ2809】[Apio2012]dispatching 可并堆
[BZOJ2809][Apio2012]dispatching Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 M ...
- bzoj 2809: [Apio2012]dispatching -- 可并堆
2809: [Apio2012]dispatching Time Limit: 10 Sec Memory Limit: 128 MB Description 在一个忍者的帮派里,一些忍者们被选中派 ...
- BZOJ2809 [Apio2012]dispatching 可并堆
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ2809 题意概括 n个点组成一棵树,每个点都有一个领导力和费用,可以让一个点当领导,然后在这个点的子 ...
- BZOJ 2809 [Apio2012]dispatching(斜堆+树形DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2809 [题目大意] 给出一棵树,求出每个点有个权值,和一个乘算值,请选取一棵子树, 并 ...
- 2809: [Apio2012]dispatching 可并堆 左偏树
https://www.lydsy.com/JudgeOnline/problem.php?id=2809 板子题wa了一下因为输出ans没有lld #include<iostream> ...
- 【bzoj2809】[Apio2012]dispatching 左偏树
2016-05-31 15:56:57 题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2809 直观的思想是当领导力确定时,尽量选择薪水少的- ...
- [Apio2012]dispatching
[Apio2012]dispatching 时间限制: 1 Sec 内存限制: 128 MB 题目描述 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一 ...
- bzoj2809 [Apio2012]dispatching(左偏树)
[Apio2012]dispatching Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 M ...
- [Apio2012]dispatching 主席树做法
bzoj 2809: [Apio2012]dispatching http://www.lydsy.com/JudgeOnline/problem.php?id=2809 Description 在一 ...
随机推荐
- codeforces 466C. Number of Ways 解题报告
题目链接:http://codeforces.com/problemset/problem/466/C 题目意思:给出一个 n 个数的序列你,问通过将序列分成三段,使得每段的和都相等的分法有多少种. ...
- linux安装netcat 运行udp服务器
liunx下安装netcat 1.下载安装包 wget https://sourceforge.net/projects/netcat/files/netcat/0.7.1/netcat-0.7.1. ...
- 组合优化学习笔记<之>从贪心算法到子集系统再到拟阵
贪心算法是用的比较多的一种优化算法,因为它过程简洁优美,而且结果有效.有些优化问题如最大权森林(MWF)是可以用贪心问题求解的,由于最小支撑树(MST)问题与MWF是等价的,所以MST也是可以用贪心算 ...
- Battle Ships(复习泛化物品**)
传送门Battle Ships Time Limit: 2 Seconds Memory Limit: 65536 KB Battle Ships is a new game which i ...
- (原创)让mongodb的secondary支持读操作
对于replica set 中的secondary 节点默认是不可读的.在写多读少的应用中,使用Replica Sets来实现读写分离.通过在连接时指定或者在主库指定slaveOk,由Secondar ...
- TextMode="Password" 赋值(小技巧)
TextMode="Password"不能在后台直接向前台赋值,但是可以用js赋值. txtUserPassword.Attributes.Add("value" ...
- 使用tableview的表头button 实现多 cell 的选择
首先声明本篇博文是作者原创,在QQ群里看到一枚猿友求助,问题描述:使用UItableView 实现在表头里点击不同的按钮,去刷新当前的界面(界面是大的 cell),自己就实现了一下. 实验原材料:故事 ...
- hibernate Criteria中or和and的用法
/s筛选去除无效数据 /* detachedCriteria.add( Restrictions.or( Restrictions.like("chanpin", &qu ...
- 1.6-1.7 定义agent 读取日志存入hdfs
一.定义agent,并运行 1.配置文件 #计划 ##收集hive的日志,存到hdfs /opt/cdh-5.3.6/hive-0.13.1-cdh5.3.6/logs/hive.log 命令:tai ...
- 【Linux学习】Vi / Vim编辑器—编辑器工作模式、vi编辑操作
Vi / Vim编辑器-编辑器工作模式.vi编辑操作 推荐一个很好的学习指南:http://www.oschina.net/translate/learn-vim-progressively 一.编辑 ...