Submission #1121334

#TimeUsernameProblemLanguageResultExecution timeMemory
1121334yeediotFireworks (APIO16_fireworks)C++17
100 / 100
152 ms35024 KiB
#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; #define pb push_back #define sz(x) (int)(x.size()) const int mxn = 3e5 + 5; inline char gc() { const static int SZ = 1 << 16; static char buf[SZ], *p1, *p2; if (p1 == p2 && (p2 = buf + fread(p1 = buf, 1, SZ, stdin), p1 == p2)) return -1; return *p1++; } inline void rd() {} template <typename T, typename... U> inline void rd(T &x, U &...y) { x = 0; bool f = 0; char c = gc(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = gc(); f && (x = -x), rd(y...); } template <typename T> inline void prt(T x) { if (x > 9)prt(x / 10); putchar((x % 10) ^ 48); } int n, m, l[mxn], p[mxn], deg[mxn]; priority_queue<long long>pq[mxn]; inline void solve(){ rd(n), rd(m); long long sum = 0; int a; for(int i = 2; i <= n + m; i++){ rd(p[i]), rd(l[i]); deg[p[i]]++; sum += l[i]; } for(int v = n + m; v >= 1; v--){ if(v > n){ pq[v].push(l[v]), pq[v].push(l[v]); } else{ for(int i = 1; i < deg[v]; i++){ pq[v].pop(); } long long R = pq[v].top(); pq[v].pop(); long long L = pq[v].top(); pq[v].pop(); pq[v].push(l[v] + L), pq[v].push(l[v] + R); } if(v == 1) break; if(sz(pq[p[v]]) < sz(pq[v])) swap(pq[p[v]], pq[v]); while(sz(pq[v])){ pq[p[v]].push(pq[v].top()); pq[v].pop(); } } pq[1].push(0); sum += pq[1].top(); while(sz(pq[1]) > 1){ sum -= pq[1].top(); pq[1].pop(); } prt(sum); } signed main(){ solve(); }

Compilation message (stderr)

fireworks.cpp: In function 'void solve()':
fireworks.cpp:37:9: warning: unused variable 'a' [-Wunused-variable]
   37 |     int a;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...