SYSU 6356 Dispatching
Dispatching
This problem will be judged on SYSU. Original ID: 6356
64-bit integer IO format: %lld Java class name: (No Java Yet)
In a sect of ninja, ninjas are dispatched to a client, and they are rewarded according to their work. In this sect, there is one ninja called the Master. Every ninja except the Master has one and only one boss. In order to preserve the confidentiality and to encourage leadership, any instructions concerning their work are always sent by a boss to his/her subordinates. It is forbidden to send instructions by other methods.
You are gathering a number of ninjas and dispatch them to a client. You have to pay salaries to dispatched ninjas. For each ninja, the amount of salary for him/her is fixed. The total amount of salaries paid to them should be within a budget. Moreover, in order to send instructions, you have to choose a ninja as a manager who can send instructions to all dispatched ninjas. When instructions are sent, a ninja who is not dispatched may mediate the transmission. The manager may or may not be dispatched. If the manager is not dispatched, he will not be paid.
You would like to maximize the satisfaction level of the client as much as possible within a budget. The satisfaction level of the client is calculated as the product of the total number of dispatched ninjas and the leadership level of the manager. For each ninja, his/her leadership level is fixed.
Write a program that, given the boss Bi, the amount of salary Ci, the leadership level Li of each ninja i (1 <= i <= N), and the budget for salaries M, outputs the maximum value of the satisfaction level of the client when the manager and dispatched ninjas are chosen so that all the conditions are fulfilled.
Input
The first line of input contains two space separated integers N(1<=N<=100000), M(1<=M<=1000000000), where N is the number of ninjas and M is the budget. The following N lines describe the boss, salary, leadership level of each ninja. The (i + 1)-th line contains three space separated integers Bi(0<=Bi<i),Ci(1<=Ci<=M), Li(1<=Li<=1000000000), describing that the boss of ninja i is ninja Bi, the amount of his/her salary is Ci, and his/her leadership level is Li. The ninja i is the Master if Bi = 0. Since the inequality Bi < i is always satisfied, for each ninja, the number of his/her boss is always smaller than the number of himself/herself.
Output
Output the maximum value of the satisfaction level of the client.
Sample Input
5 4
0 3 3
1 3 5
2 2 2
1 2 4
2 3 1
Sample Output
6
Source
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
int L[maxn],R[maxn],V[maxn],D[maxn],Le[maxn],C[maxn],cnt[maxn],n,m;
LL sum[maxn],ret;
vector<int>g[maxn];
int Merge(int x,int y){
if(!x || !y) return x|y;
if(V[x] < V[y]) swap(x,y);
R[x] = Merge(R[x],y);
if(D[L[x]] < D[R[x]]) swap(L[x],R[x]);
D[x] = D[R[x]] + ;
sum[x] = sum[L[x]] + sum[R[x]] + C[x];
cnt[x] = cnt[L[x]] + cnt[R[x]] + ;
return x;
}
int pop(int root){
int newRoot = Merge(L[root],R[root]);
L[root] = R[root] = D[root] = ;
return newRoot;
}
int dfs(int u){
int root = u;
cnt[u] = ;
V[u] = sum[u] = C[u];
for(int i = g[u].size()-; i >= ; --i)
root = Merge(root,dfs(g[u][i]));
while(sum[root] > m) root = pop(root);
ret = max(ret,(LL)cnt[root]*Le[u]);
return root;
}
int main(){
scanf("%d%d",&n,&m);
for(int i = ,B; i <= n; ++i){
scanf("%d%d%d",&B,C+i,Le+i);
g[B].push_back(i);
}
dfs();
printf("%lld\n",ret);
return ;
}
SYSU 6356 Dispatching的更多相关文章
- BZOJ2809: [Apio2012]dispatching
传送门 主席树经典题. 首先把树搞出来,然后搞出来DFS序.然后离散化点权,在DFS序上建立主席树. 对于每个点对应的区间,查找对应的区间最大的点数即可. //BZOJ2809 //by Cydiat ...
- 【bzoj2809】[Apio2012]dispatching 左偏树
2016-05-31 15:56:57 题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2809 直观的思想是当领导力确定时,尽量选择薪水少的- ...
- 【BZOJ-2809】dispatching派遣 Splay + 启发式合并
2809: [Apio2012]dispatching Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2334 Solved: 1192[Submi ...
- BZOJ 2809: [Apio2012]dispatching( 平衡树 + 启发式合并 )
枚举树上的每个结点做管理者, 贪心地取其子树中薪水较低的, 算出这个结点为管理者的满意度, 更新答案. 用平衡树+启发式合并, 时间复杂度为O(N log²N) ------------------- ...
- Exception dispatching input event. use XlistView
今天上午解决Bug,一个上午的时间: log: 11-01 14:49:14.826: E/InputEventReceiver(30810): Exception dispatching input ...
- [Apio2012]dispatching
[Apio2012]dispatching 时间限制: 1 Sec 内存限制: 128 MB 题目描述 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一 ...
- bzoj2809 [Apio2012]dispatching(左偏树)
[Apio2012]dispatching Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 M ...
- 线段树模板(HDU 6356 Glad You Came)
题目: HDU 6356 http://acm.hdu.edu.cn/showproblem.php?pid=6356 很裸的线段树 #include<bits/stdc++.h> #de ...
- [Apio2012]dispatching 主席树做法
bzoj 2809: [Apio2012]dispatching http://www.lydsy.com/JudgeOnline/problem.php?id=2809 Description 在一 ...
随机推荐
- cocos2d-x3.0 关于CCAnimate 的一些资料
CCAnimate 能够理解为一个动画播放器, CCAnimation 能够理解为一个动画内容.它须要播放器才干播放动画. 与它们相关的一些类例如以下 SpriteFrameCache 精灵帧缓存 ...
- 高速掌握Lua 5.3 —— I/O库 (1)
Q:什么是"Simple Model"? A:全部的文件操作都基于一个默认的输入文件和一个默认的输出文件.这就意味着同一时间对于输入和输出来说,仅仅可操作一个文件(默认的文件). ...
- BZOJ2179: FFT快速傅立叶 & caioj1450:【快速傅里叶变换】大整数乘法
[传送门:BZOJ2179&caioj1450] 简要题意: 给出两个超级大的整数,求出a*b 题解: Rose_max出的一道FFT例题,卡掉高精度 = =(没想到BZOJ也有) 只要把a和 ...
- Mysql-in查询问题
Mysql-in查询问题 标签(空格分隔): mysql 问题:mysql用in语法查询出来的数据少了好多! 我的实际情况: 数据表: content字段记录着一些选项的id,多个选项用逗号隔开,比如 ...
- Android RecyclerView 水平滚动+自动循环轮播
主要处理的地方: 1.RecyclerView中Adapter的item个人可以无限轮询. 2.RecyclerView自动滑动 3.手指按下时滑动停止,手指抬起后继续自动滑动 public clas ...
- $.widget 编写jQueryUI插件(widget)
转自:MainTao: 编写jQueryUI插件(widget) 使用jQueryUI的widget来写插件,相比于基本的jquery插件有一些好处: * 方便实现继承,代码重用 * 默认是单例 * ...
- 《剑指offer》栈的压入、弹出序列
一.题目描述 输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序.假设压入栈的所有数字均不相等.例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压 ...
- http://www.open-open.com/lib/tag/ReactiveCocoa
http://www.open-open.com/lib/tag/ReactiveCocoa
- Python3基础笔记--基础知识
目录: 一.变量问题 二.运算符总结 三.字符串问题 四.数据结构 五.文件操作 一.变量问题 变量存储在内存中的值.这就意味着在创建变量时会在内存中开辟一个空间.它自始至终都是在内存中活动,只有指明 ...
- 在windows下如何新建爬虫虚拟环境和进行scrapy安装
Scrapy是Python开发的一个快速.高层次的屏幕抓取和web抓取框架,用于抓取web站点并从页面中提取结构化的数据.Scrapy吸引人的地方在于它是一个框架,任何人都可以根据需求方便的修改.Sc ...