Submission #714933

#TimeUsernameProblemLanguageResultExecution timeMemory
714933Spade1Fireworks (APIO16_fireworks)C++14
100 / 100
228 ms75620 KiB
#include<bits/stdc++.h> //#include <grader.h> #define pii pair<int, int> #define pll pair<long long, long long> #define ll long long #define ld long double #define st first #define nd second #define pb push_back #define INF INT_MAX using namespace std; const int N = 3e5 + 10; vector<int> adj[N]; priority_queue<ll> q[N]; ll c[N]; void dfs(int i) { if (adj[i].empty()) { q[i].push(c[i]); q[i].push(c[i]); return; } for (auto j : adj[i]) { dfs(j); if (q[i].size() < q[j].size()) swap(q[i], q[j]); while (!q[j].empty()) q[i].push(q[j].top()), q[j].pop(); } for (int k = 1; k < adj[i].size(); ++k) q[i].pop(); ll a = q[i].top()+c[i]; q[i].pop(); ll b = q[i].top()+c[i]; q[i].pop(); q[i].push(a); q[i].push(b); } void solve() { int n, m; cin >> n >> m; for (int i = 2; i <= n+m; ++i) { int p; cin >> p >> c[i]; adj[p].pb(i); } ll ans = 0; for (int i = 2; i <= n+m; ++i) ans += c[i]; dfs(1); q[1].pop(); while (!q[1].empty()) ans -= q[1].top(), q[1].pop(); cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }

Compilation message (stderr)

fireworks.cpp: In function 'void dfs(int)':
fireworks.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for (int k = 1; k < adj[i].size(); ++k) q[i].pop();
      |                     ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...