제출 #68545

#제출 시각아이디문제언어결과실행 시간메모리
68545evpipisFireworks (APIO16_fireworks)C++11
100 / 100
367 ms55660 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; const int len = 3e5+5; int par[len], val[len]; vector<int> adj[len]; ll a[len], b[len]; priority_queue<ll> *pq[len]; int main(){ int n, m; scanf("%d %d", &n, &m); for (int i = 2; i <= n+m; i++){ scanf("%d %d", &par[i], &val[i]); adj[par[i]].pb(i); } for (int u = n+m; u >= 1; u--){ if (u > n){ pq[u] = new priority_queue<ll>(); (*pq[u]).push(val[u]); (*pq[u]).push(val[u]); a[u] = 1; b[u] = -val[u]; } else{ int mx = 0, big; for (int j = 0; j < adj[u].size(); j++){ int v = adj[u][j]; if ((*pq[v]).size() > mx) mx = (*pq[v]).size(), big = v; } pq[u] = pq[big]; a[u] = a[big]; b[u] = b[big]; for (int j = 0; j < adj[u].size(); j++){ int v = adj[u][j]; if (v == big) continue; a[u] += a[v]; b[u] += b[v]; while (!(*pq[v]).empty()){ (*pq[u]).push((*pq[v]).top()); (*pq[v]).pop(); } } for (int j = 1; j < adj[u].size(); j++){ a[u] -= 1; b[u] += (*pq[u]).top(); (*pq[u]).pop(); } ll p2, p1; p2 = (*pq[u]).top(), (*pq[u]).pop(); p1 = (*pq[u]).top(), (*pq[u]).pop(); // a[u] = a[u] b[u] = b[u]-val[u]; (*pq[u]).push(p1+val[u]); (*pq[u]).push(p2+val[u]); } } printf("%lld\n", a[1]*(*pq[1]).top() + b[1]); return 0; }

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

fireworks.cpp: In function 'int main()':
fireworks.cpp:31:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 0; j < adj[u].size(); j++){
                             ~~^~~~~~~~~~~~~~~
fireworks.cpp:33:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if ((*pq[v]).size() > mx)
                     ~~~~~~~~~~~~~~~~^~~~
fireworks.cpp:41:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 0; j < adj[u].size(); j++){
                             ~~^~~~~~~~~~~~~~~
fireworks.cpp:53:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j = 1; j < adj[u].size(); j++){
                             ~~^~~~~~~~~~~~~~~
fireworks.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
fireworks.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &par[i], &val[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
fireworks.cpp:37:27: warning: 'big' may be used uninitialized in this function [-Wmaybe-uninitialized]
             pq[u] = pq[big];
                     ~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...