bzoj2806 [apio2012]dispatching "can be stacked"

Source: Internet
Author: User


Save the code that can be stacked with the template.

#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;sca NF ("%d%d", &n, &m); for (int i = 1; I <= n; ++i) {scanf ("%d%d%d", fa + I, salary + I, leads + i); ist (fa[i], i);} DFS (1);p rintf ("%lld\n", ans); return 0;}


bzoj2806 [apio2012]dispatching "can be stacked"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.