【BZOJ2809】【APIO2012】dispatching
2018-03-18 19:45
411 查看
【题目链接】
点击打开链接
【思路要点】
补档博客,无题解。
【代码】
点击打开链接
【思路要点】
补档博客,无题解。
【代码】
#include<bits/stdc++.h> using namespace std; #define MAXN 100005 struct Node { int father, size; long long value, sum; int child[2], depth[2]; }; Node a[MAXN]; vector <int> t[MAXN]; int n, master, b[MAXN], root[MAXN]; long long m, ans, c[MAXN], l[MAXN]; int merge(int x, int y) { if (x == 0) return y; if (y == 0) return x; if (a[x].value < a[y].value) swap(x, y); a[x].size += a[y].size; a[x].sum += a[y].sum; a[x].child[1] = merge(a[x].child[1], y); a[a[x].child[1]].father = x; a[x].depth[1] = 1 + max(a[a[x].child[1]].depth[0], a[a[x].child[1]].depth[1]); if (a[x].depth[1] > a[x].depth[0]) { swap(a[x].depth[0], a[x].depth[1]); swap(a[x].child[0], a[x].child[1]); } return x; } int del(int x) { int tmp = merge(a[x].child[0], a[x].child[1]); a[tmp].father = 0; return tmp; } void work(int pos) { for (unsigned i = 0; i < t[pos].size(); i++) { work(t[pos][i]); root[pos] = merge(root[pos], root[t[pos][i]]); } while (a[root[pos]].sum > m) root[pos] = del(root[pos]); ans = max(ans, l[pos] * a[root[pos]].size); } int main() { scanf("%d%lld", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d%lld%lld", &b[i], &c[i], &l[i]); a[i].value = c[i]; a[i].sum = c[i]; a[i].size = 1; root[i] = i; if (b[i] != 0) t[b[i]].push_back(i); else master = i; } work(master); printf("%lld\n", ans); return 0; }
相关文章推荐
- [BZOJ2809][Apio2012]dispatching(可并堆)
- BZOJ 2809: [Apio2012]dispatching 可并堆
- 【BZOJ 2809】【APIO 2012】dispatching
- bzoj2809: [Apio2012]dispatching
- bzoj 2809: [Apio2012]dispatching
- 【BZOJ 2809】[Apio2012]dispatching 可并堆
- bzoj2809 [Apio2012]dispatching
- 【bzoj2809】 Apio2012—dispatching
- 【APIO2012】【BZOJ2809】派遣dispatching
- [APIO2012]bzoj2809 dispatching 左偏树
- 【BZOJ】【2809】【APIO2012】派遣dispatching
- [bzoj2809][Apio2012][dispatching] (可并堆)
- bzoj 2809 [Apio2012]dispatching
- 【bzoj2809】 Apio2012—dispatching
- 【BZOJ2809】[Apio2012]dispatching 可并堆
- 【APIO2012】bzoj2809 dispatching
- [可并堆] BZOJ 2809 [Apio2012]dispatching
- BZOJ2809(Apio2012)[dispatching]--左偏树
- [左偏树]BZOJ 2809——[Apio2012]dispatching
- 可并堆-bzoj2809: [Apio2012]dispatching