제출 #139933

#제출 시각아이디문제언어결과실행 시간메모리
139933nvmdavaFireworks (APIO16_fireworks)C++17
100 / 100
457 ms93604 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long int p[300005]; int b[300005]; ll a[300005]; priority_queue<pair<long long, int> > pq[300005]; vector<int> ch[300005]; void dfs(int v){ int big = 0; for(int& x : ch[v]){ dfs(x); if(pq[big].size() < pq[x].size()) big = x; } if(big == 0){ pq[v].push({0, -1}); pq[v].push({a[v], 1}); pq[v].push({a[v], 1}); return; } swap(pq[big], pq[v]); int g = ch[v].size(); for(auto& x : ch[v]){ if(x == big) continue; while(!pq[x].empty()){ pq[v].push(pq[x].top()); pq[x].pop(); } } ll t, t2; while(g > -1){ t2 = t; t = pq[v].top().first; g -= pq[v].top().second; pq[v].pop(); } pq[v].push({t + a[v], 1}); pq[v].push({t + a[v] + t2 - t, 1}); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin>>n>>m; ll y = 0; for(int i = 2; i <= n + m; i++){ cin>>p[i]>>a[i]; y += a[i]; ch[p[i]].push_back(i); } dfs(1); ll t = pq[1].top().first; while(!pq[1].empty()){ y += (t - pq[1].top().first) * pq[1].top().second; pq[1].pop(); } cout<<y; }

컴파일 시 표준 에러 (stderr) 메시지

fireworks.cpp: In function 'void dfs(int)':
fireworks.cpp:41:25: warning: 't2' may be used uninitialized in this function [-Wmaybe-uninitialized]
    pq[v].push({t + a[v] + t2 - t, 1});
                ~~~~~~~~~^~~~
fireworks.cpp:40:18: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
    pq[v].push({t + a[v], 1});
                ~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...