SYSU 6356 Dispatching

Dispatching

Time Limit: 3000ms

Memory Limit: 262144KB

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

APIO 2012, 2012年每周一赛第十三场

解题:左偏树啊。学了好久。。。

这道题目,就是用左偏树维护一些人,使得这些人的所付的薪水不超过M,如果超过了,那么删除薪水最大的,直到这些人的薪水和不超过M

等下试试 持久化的Treap

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long LL;
 4 const int maxn = 100005;
 5 int L[maxn],R[maxn],V[maxn],D[maxn],Le[maxn],C[maxn],cnt[maxn],n,m;
 6 LL sum[maxn],ret;
 7 vector<int>g[maxn];
 8 int Merge(int x,int y){
 9     if(!x || !y) return x|y;
10     if(V[x] < V[y]) swap(x,y);
11     R[x] = Merge(R[x],y);
12     if(D[L[x]] < D[R[x]]) swap(L[x],R[x]);
13     D[x] = D[R[x]] + 1;
14     sum[x] = sum[L[x]] + sum[R[x]] + C[x];
15     cnt[x] = cnt[L[x]] + cnt[R[x]] + 1;
16     return x;
17 }
18 int pop(int root){
19     int newRoot = Merge(L[root],R[root]);
20     L[root] = R[root] = D[root] = 0;
21     return newRoot;
22 }
23 int dfs(int u){
24     int root = u;
25     cnt[u] = 1;
26     V[u] = sum[u] = C[u];
27     for(int i = g[u].size()-1; i >= 0; --i)
28         root = Merge(root,dfs(g[u][i]));
29     while(sum[root] > m) root = pop(root);
30     ret = max(ret,(LL)cnt[root]*Le[u]);
31     return root;
32 }
33 int main(){
34     scanf("%d%d",&n,&m);
35     for(int i = 1,B; i <= n; ++i){
36         scanf("%d%d%d",&B,C+i,Le+i);
37         g[B].push_back(i);
38     }
39     dfs(1);
40     printf("%lld\n",ret);
41     return 0;
42 }

时间: 2024-11-25 18:52:12

SYSU 6356 Dispatching的相关文章

bzoj2809[Apio2012]dispatching

bzoj2809[Apio2012]dispatching 题意: n个点组成一棵树,每个点都有一个领导力和费用,可以让一个点当领导,然后在这个点的子树中选择一些费用之和不超过m的点,得到领导的领导力乘选择的点的个数(领导可不被选择)的利润.求利润最大值.n≤100000 题解: 可并堆.可以得到一个结论,就是在子树中选点的时候,先选所有点,如果费用超了,就不断把费用最大的剔除,知道费用不超,这样得到的选点数量最大,这过程可以用堆维护.同时每个点的堆都可以由子树的堆合并得到,所以需要可并堆. 代

【BZOJ 2809】2809: [Apio2012]dispatching (左偏树)

2809: [Apio2012]dispatching Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 Master以外,每名忍者都有且仅有一个上级.为保密,同时增强忍者们的领导力,所有与他们工作相关的指令总是由上级发送给他的直接下属,而不允许通过其他的方式发送.现在你要招募一批忍者,并把它们派遣给顾客.你需要为每个被派遣的忍者 支付一定的薪水,同时使得支付的薪水总额不超过你的预算.另外,为

【左偏树】【APIO】Dispatching

2809: [Apio2012]dispatching Time Limit: 10 Sec Memory Limit: 128 MB Submit: 1932 Solved: 967 Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 Master以外,每名忍者都有且仅有一个上级.为保密,同时增强忍者们的领导力,所有与他们工作相关的指令总是由上级发送给他的直接下属,而不允许通过其他的方式发送.

AC日记——dispatching bzoj 2809

2809: [Apio2012]dispatching Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3290  Solved: 1740[Submit][Status][Discuss] Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 Master以外,每名忍者都有且仅有一个上级.为保密,同时增强忍者们的领导力,所有与他们工作相关的指令总是

循环分发消息(Round-robin dispatching)

在上节中,我们发送了一个"Hello World!"字符串消息.现在发送多个字符串消息表示复杂任务.我们现在像图片重置大小,渲染PDF文件这样的真实任务,但我们使用 Thread.sleep() 假装正在我们忙.我们将字符串中的点的数量作为其复杂性:每个点都占1秒钟"工作".例如,一个包含"..."这样的假任务就会需要三秒钟. NewTask.java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

[Apio2012]dispatching

[Apio2012]dispatching 时间限制: 1 Sec  内存限制: 128 MB 题目描述 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 Master以外,每名忍者都有且仅有一个上级.为保密,同时增强忍者们的领导力,所有与他们工作相关的指令总是由上级发送给他的直接下属,而不允许通过其他的方式发送.现在你要招募一批忍者,并把它们派遣给顾客.你需要为每个被派遣的忍者 支付一定的薪水,同时使得支付的薪水总

【BZOJ-2809】dispatching派遣 Splay + 启发式合并

2809: [Apio2012]dispatching Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2334  Solved: 1192[Submit][Status][Discuss] Description 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿.在这个帮派里,有一名忍者被称之为 Master.除了 Master以外,每名忍者都有且仅有一个上级.为保密,同时增强忍者们的领导力,所有与他们工作相关的指令总是

FDU&amp;SYSU报告

嘛,今天有点不高兴,也没什么可做的,写点东西回顾整理下.FDU:    先回顾一下,参加fdu夏令营前大概的状况,主要是省选期末双挂,有点不爽,然后心里不知道怎么总有一种侥幸感,总觉得自己未来还是很光明啊,靠着之前准备省选的实力就能吃饭啊什么的,假期没怎么刷题.    八月开学补课,群众氛围挺浮躁的,我也是处于一个天天刷fdu招生网的状态.然后搞资料的时候各种领导放假,差一点就没有校长的签字了,各种蛋疼.把资料完全寄出的时候稍稍松了一口气,接下来还是刷,但是是刷网站,不是刷题= =.    终于

SYSU暑假热身赛D

D - Rope in the Labyrinth Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice URAL 1145 Description A labyrinth with rectangular form and size m × n is divided into square cells with sides' length 1 by l