BZOJ2809 [Apio2012]dispatching
2014-12-20 16:26
435 查看
看来蒟蒻我还是直接退役算了。。。
此题就是维护子树的和,删除子树中当前最大元素,并且可以合并两个子树信息,想到了左偏树。。。
做完了233
View Code
那个什么的扯淡教育部给我去死!!!
此题就是维护子树的和,删除子树中当前最大元素,并且可以合并两个子树信息,想到了左偏树。。。
做完了233
/************************************************************** Problem: 2809 User: rausen Language: C++ Result: Accepted Time:804 ms Memory:7624 kb ****************************************************************/ #include <cstdio> #include <algorithm> using namespace std; typedef long long ll; const int N = 100005; struct heap{ int v, l, r, dep; }h ; int cnt_heap; struct edge { int next, to; edge() {} edge(int _n, int _t) : next(_n), to(_t) {} } e ; int first , tot; struct tree_node { int cost, l, root; ll sum, sz; } tr ; int n, m; ll ans; inline int read() { int x = 0, sgn = 1; char ch = getchar(); while (ch < '0' || '9' < ch) { if (ch == '-') sgn = -1; ch = getchar(); } while ('0' <= ch && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return sgn * x; } inline void add_edge(int x, int y) { e[++tot] = edge(first[x], y); first[x] = tot; } inline int new_heap(int x) { h[++cnt_heap].v = x; h[cnt_heap].l = h[cnt_heap].r = h[cnt_heap].dep = 0; return cnt_heap; } int Merge(int x, int y) { if (!x || !y) return x + y; if (h[x].v < h[y].v) swap(x, y); h[x].r = Merge(h[x].r, y); if (h[h[x].l].dep < h[h[x].r].dep) swap(h[x].l, h[x].r); h[x].dep = h[h[x].r].dep + 1; return x; } inline int Top(int p) { return h[p].v; } void Pop(int &p) { p = Merge(h[p].l, h[p].r); } void dfs(int p) { int x, y; tr[p].root = new_heap(tr[p].cost); tr[p].sum = tr[p].cost, tr[p].sz = 1; for (x = first[p]; x; x = e[x].next) { dfs(y = e[x].to); tr[p].sum += tr[y].sum, tr[p].sz += tr[y].sz; tr[p].root = Merge(tr[p].root, tr[y].root); } while (tr[p].sum > m) { tr[p].sum -= Top(tr[p].root), Pop(tr[p].root); --tr[p].sz; } ans = max(ans, tr[p].sz * tr[p].l); } int main() { int i, x; n = read(), m = read(); for (i = 1; i <= n; ++i) { x = read(); add_edge(x, i); tr[i].cost = read(), tr[i].l = read(); } dfs(1); printf("%lld\n", ans); return 0; }
View Code
那个什么的扯淡教育部给我去死!!!
相关文章推荐
- BZOJ 2809 [Apio2012]dispatching 可并堆
- bzoj2809: [Apio2012]dispatching
- [BZOJ2809] [APIO2012] dispatching - 可并堆
- BZOJ 2809 APIO 2012 dispatching 平衡树启示式合并
- 【bzoj2809】[Apio2012]dispatching 贪心+可并堆
- BZOJ 2809 [Apio2012]dispatching
- bzoj 2809: [Apio2012]dispatching【dfs序+主席树】
- bzoj2809: [Apio2012]dispatching
- [BZOJ2809][Apio2012]dispatching(枚举&dfs序+主席树||可并堆||splay+启发式合并)
- bzoj 2809: [Apio2012]dispatching
- bzoj 2809: [Apio2012]dispatching
- 【BZOJ 2809】 [Apio2012]dispatching
- 【左偏树】BZOJ2809-[APIO2012]dispatching
- BZOJ 2809: [Apio2012]dispatching( 平衡树 + 启发式合并 )
- BZOJ2809:[Apio2012]dispatching——题解
- BZOJ2809 [Apio2012]dispatching 解题报告
- [dfs序+主席树] BZOJ2809: [Apio2012]dispatching
- BZOJ 2809 [Apio2012]dispatching(斜堆+树形DP)
- 【BZOJ 2809】【APIO 2012】dispatching
- bzoj2809: [Apio2012]dispatching