Submission #1002220

#TimeUsernameProblemLanguageResultExecution timeMemory
1002220dimashhhFireworks (APIO16_fireworks)C++17
26 / 100
738 ms524288 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 4e5 + 30, MOD = 1e9 + 7; #define int ll int n,m; vector<pair<int,int>> g[N]; multiset<ll> st[N]; ll h[N],l[N],r[N]; int mx[N]; void merge(int v,int to){ if((int)st[v].empty() < (int)st[to].size()){ st[v].swap(st[to]); swap(mx[v],mx[to]); swap(l[v],l[to]); swap(r[v],r[to]); } mx[v]+=mx[to]; for(int j:st[to]){ st[v].insert(j); } } void dfs(int v,int W = 0){ if(g[v].empty()){ st[v].insert(W); st[v].insert(W); mx[v] = 1; h[v] = 0; l[v] = r[v] = W; return; } for(auto [to,w]:g[v]){ dfs(to,w); merge(v,to); } while(mx[v] > 1){ mx[v]--; st[v].erase(st[v].find(*st[v].rbegin())); } ll x = (*st[v].rbegin()); st[v].erase(st[v].find(*st[v].rbegin())); ll y = (*st[v].rbegin()); st[v].erase(st[v].find(*st[v].rbegin())); st[v].insert(x + W); st[v].insert(y + W); r[v] = (*st[v].rbegin()); l[v] = (*(++(st[v].rbegin()))); } ll E = 0; void test(){ cin >> n >> m; for(int i = 2;i <= n + m;i++){ int a,b; cin >> a >> b; g[a].push_back({i,b}); E += b; } dfs(1); st[1].erase(--st[1].end()); ll H = 0; for(int i:st[1]){ E -= i; } cout << E << '\n'; } signed main() { ios_base::sync_with_stdio(false);cin.tie(0); int t = 1; // cin >> t; while(t--){ test(); } }

Compilation message (stderr)

fireworks.cpp: In function 'void test()':
fireworks.cpp:63:8: warning: unused variable 'H' [-Wunused-variable]
   63 |     ll H = 0;
      |        ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...