답안 #68537

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68537 2018-08-17T09:23:04 Z evpipis Fireworks (APIO16_fireworks) C++11
26 / 100
10 ms 7716 KB
#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<int> *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<int>();
            (*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++){
                int x = (*pq[u]).top();
                (*pq[u]).pop();

                a[u] -= 1;
                b[u] += x;
            }

            int p2, p1;
            p2 = (*pq[u]).top(), (*pq[u]).pop();
            p1 = (*pq[u]).top(), (*pq[u]).pop();

            // a[u] = a[u]
            b[u] = p2*a[u]+b[u] - p2-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;
}

Compilation message

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];
                     ~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7516 KB Output is correct
3 Correct 9 ms 7520 KB Output is correct
4 Correct 8 ms 7520 KB Output is correct
5 Correct 8 ms 7520 KB Output is correct
6 Correct 8 ms 7520 KB Output is correct
7 Correct 7 ms 7524 KB Output is correct
8 Correct 8 ms 7524 KB Output is correct
9 Correct 8 ms 7524 KB Output is correct
10 Correct 9 ms 7524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7576 KB Output is correct
2 Correct 8 ms 7700 KB Output is correct
3 Correct 9 ms 7716 KB Output is correct
4 Correct 8 ms 7716 KB Output is correct
5 Correct 8 ms 7716 KB Output is correct
6 Correct 8 ms 7716 KB Output is correct
7 Correct 8 ms 7716 KB Output is correct
8 Correct 8 ms 7716 KB Output is correct
9 Correct 8 ms 7716 KB Output is correct
10 Correct 8 ms 7716 KB Output is correct
11 Correct 8 ms 7716 KB Output is correct
12 Correct 10 ms 7716 KB Output is correct
13 Correct 9 ms 7716 KB Output is correct
14 Correct 10 ms 7716 KB Output is correct
15 Correct 8 ms 7716 KB Output is correct
16 Correct 8 ms 7716 KB Output is correct
17 Correct 8 ms 7716 KB Output is correct
18 Correct 8 ms 7716 KB Output is correct
19 Correct 10 ms 7716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7516 KB Output is correct
3 Correct 9 ms 7520 KB Output is correct
4 Correct 8 ms 7520 KB Output is correct
5 Correct 8 ms 7520 KB Output is correct
6 Correct 8 ms 7520 KB Output is correct
7 Correct 7 ms 7524 KB Output is correct
8 Correct 8 ms 7524 KB Output is correct
9 Correct 8 ms 7524 KB Output is correct
10 Correct 9 ms 7524 KB Output is correct
11 Correct 8 ms 7576 KB Output is correct
12 Correct 8 ms 7700 KB Output is correct
13 Correct 9 ms 7716 KB Output is correct
14 Correct 8 ms 7716 KB Output is correct
15 Correct 8 ms 7716 KB Output is correct
16 Correct 8 ms 7716 KB Output is correct
17 Correct 8 ms 7716 KB Output is correct
18 Correct 8 ms 7716 KB Output is correct
19 Correct 8 ms 7716 KB Output is correct
20 Correct 8 ms 7716 KB Output is correct
21 Correct 8 ms 7716 KB Output is correct
22 Correct 10 ms 7716 KB Output is correct
23 Correct 9 ms 7716 KB Output is correct
24 Correct 10 ms 7716 KB Output is correct
25 Correct 8 ms 7716 KB Output is correct
26 Correct 8 ms 7716 KB Output is correct
27 Correct 8 ms 7716 KB Output is correct
28 Correct 8 ms 7716 KB Output is correct
29 Correct 10 ms 7716 KB Output is correct
30 Incorrect 9 ms 7716 KB Output isn't correct
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7516 KB Output is correct
3 Correct 9 ms 7520 KB Output is correct
4 Correct 8 ms 7520 KB Output is correct
5 Correct 8 ms 7520 KB Output is correct
6 Correct 8 ms 7520 KB Output is correct
7 Correct 7 ms 7524 KB Output is correct
8 Correct 8 ms 7524 KB Output is correct
9 Correct 8 ms 7524 KB Output is correct
10 Correct 9 ms 7524 KB Output is correct
11 Correct 8 ms 7576 KB Output is correct
12 Correct 8 ms 7700 KB Output is correct
13 Correct 9 ms 7716 KB Output is correct
14 Correct 8 ms 7716 KB Output is correct
15 Correct 8 ms 7716 KB Output is correct
16 Correct 8 ms 7716 KB Output is correct
17 Correct 8 ms 7716 KB Output is correct
18 Correct 8 ms 7716 KB Output is correct
19 Correct 8 ms 7716 KB Output is correct
20 Correct 8 ms 7716 KB Output is correct
21 Correct 8 ms 7716 KB Output is correct
22 Correct 10 ms 7716 KB Output is correct
23 Correct 9 ms 7716 KB Output is correct
24 Correct 10 ms 7716 KB Output is correct
25 Correct 8 ms 7716 KB Output is correct
26 Correct 8 ms 7716 KB Output is correct
27 Correct 8 ms 7716 KB Output is correct
28 Correct 8 ms 7716 KB Output is correct
29 Correct 10 ms 7716 KB Output is correct
30 Incorrect 9 ms 7716 KB Output isn't correct
31 Halted 0 ms 0 KB -