답안 #68545

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68545 2018-08-17T09:33:28 Z evpipis Fireworks (APIO16_fireworks) C++11
100 / 100
367 ms 55660 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<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;
}

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 9 ms 7416 KB Output is correct
3 Correct 8 ms 7432 KB Output is correct
4 Correct 8 ms 7508 KB Output is correct
5 Correct 8 ms 7584 KB Output is correct
6 Correct 8 ms 7676 KB Output is correct
7 Correct 9 ms 7676 KB Output is correct
8 Correct 9 ms 7788 KB Output is correct
9 Correct 10 ms 7788 KB Output is correct
10 Correct 9 ms 7788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7788 KB Output is correct
2 Correct 8 ms 7788 KB Output is correct
3 Correct 8 ms 7788 KB Output is correct
4 Correct 9 ms 7788 KB Output is correct
5 Correct 8 ms 7788 KB Output is correct
6 Correct 9 ms 7788 KB Output is correct
7 Correct 8 ms 7788 KB Output is correct
8 Correct 8 ms 7788 KB Output is correct
9 Correct 9 ms 7788 KB Output is correct
10 Correct 8 ms 7788 KB Output is correct
11 Correct 8 ms 7788 KB Output is correct
12 Correct 9 ms 7788 KB Output is correct
13 Correct 10 ms 7788 KB Output is correct
14 Correct 8 ms 7788 KB Output is correct
15 Correct 9 ms 7788 KB Output is correct
16 Correct 11 ms 7788 KB Output is correct
17 Correct 9 ms 7788 KB Output is correct
18 Correct 9 ms 7788 KB Output is correct
19 Correct 8 ms 7788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 9 ms 7416 KB Output is correct
3 Correct 8 ms 7432 KB Output is correct
4 Correct 8 ms 7508 KB Output is correct
5 Correct 8 ms 7584 KB Output is correct
6 Correct 8 ms 7676 KB Output is correct
7 Correct 9 ms 7676 KB Output is correct
8 Correct 9 ms 7788 KB Output is correct
9 Correct 10 ms 7788 KB Output is correct
10 Correct 9 ms 7788 KB Output is correct
11 Correct 8 ms 7788 KB Output is correct
12 Correct 8 ms 7788 KB Output is correct
13 Correct 8 ms 7788 KB Output is correct
14 Correct 9 ms 7788 KB Output is correct
15 Correct 8 ms 7788 KB Output is correct
16 Correct 9 ms 7788 KB Output is correct
17 Correct 8 ms 7788 KB Output is correct
18 Correct 8 ms 7788 KB Output is correct
19 Correct 9 ms 7788 KB Output is correct
20 Correct 8 ms 7788 KB Output is correct
21 Correct 8 ms 7788 KB Output is correct
22 Correct 9 ms 7788 KB Output is correct
23 Correct 10 ms 7788 KB Output is correct
24 Correct 8 ms 7788 KB Output is correct
25 Correct 9 ms 7788 KB Output is correct
26 Correct 11 ms 7788 KB Output is correct
27 Correct 9 ms 7788 KB Output is correct
28 Correct 9 ms 7788 KB Output is correct
29 Correct 8 ms 7788 KB Output is correct
30 Correct 8 ms 7788 KB Output is correct
31 Correct 9 ms 7804 KB Output is correct
32 Correct 9 ms 7804 KB Output is correct
33 Correct 12 ms 7932 KB Output is correct
34 Correct 12 ms 7932 KB Output is correct
35 Correct 11 ms 7936 KB Output is correct
36 Correct 10 ms 8060 KB Output is correct
37 Correct 14 ms 8188 KB Output is correct
38 Correct 13 ms 8188 KB Output is correct
39 Correct 14 ms 8188 KB Output is correct
40 Correct 11 ms 8188 KB Output is correct
41 Correct 12 ms 8188 KB Output is correct
42 Correct 12 ms 8188 KB Output is correct
43 Correct 12 ms 8188 KB Output is correct
44 Correct 14 ms 8188 KB Output is correct
45 Correct 12 ms 8188 KB Output is correct
46 Correct 15 ms 8492 KB Output is correct
47 Correct 13 ms 8492 KB Output is correct
48 Correct 11 ms 8492 KB Output is correct
49 Correct 15 ms 8492 KB Output is correct
50 Correct 12 ms 8492 KB Output is correct
51 Correct 12 ms 8492 KB Output is correct
52 Correct 15 ms 8492 KB Output is correct
53 Correct 12 ms 8492 KB Output is correct
54 Correct 13 ms 8492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 9 ms 7416 KB Output is correct
3 Correct 8 ms 7432 KB Output is correct
4 Correct 8 ms 7508 KB Output is correct
5 Correct 8 ms 7584 KB Output is correct
6 Correct 8 ms 7676 KB Output is correct
7 Correct 9 ms 7676 KB Output is correct
8 Correct 9 ms 7788 KB Output is correct
9 Correct 10 ms 7788 KB Output is correct
10 Correct 9 ms 7788 KB Output is correct
11 Correct 8 ms 7788 KB Output is correct
12 Correct 8 ms 7788 KB Output is correct
13 Correct 8 ms 7788 KB Output is correct
14 Correct 9 ms 7788 KB Output is correct
15 Correct 8 ms 7788 KB Output is correct
16 Correct 9 ms 7788 KB Output is correct
17 Correct 8 ms 7788 KB Output is correct
18 Correct 8 ms 7788 KB Output is correct
19 Correct 9 ms 7788 KB Output is correct
20 Correct 8 ms 7788 KB Output is correct
21 Correct 8 ms 7788 KB Output is correct
22 Correct 9 ms 7788 KB Output is correct
23 Correct 10 ms 7788 KB Output is correct
24 Correct 8 ms 7788 KB Output is correct
25 Correct 9 ms 7788 KB Output is correct
26 Correct 11 ms 7788 KB Output is correct
27 Correct 9 ms 7788 KB Output is correct
28 Correct 9 ms 7788 KB Output is correct
29 Correct 8 ms 7788 KB Output is correct
30 Correct 8 ms 7788 KB Output is correct
31 Correct 9 ms 7804 KB Output is correct
32 Correct 9 ms 7804 KB Output is correct
33 Correct 12 ms 7932 KB Output is correct
34 Correct 12 ms 7932 KB Output is correct
35 Correct 11 ms 7936 KB Output is correct
36 Correct 10 ms 8060 KB Output is correct
37 Correct 14 ms 8188 KB Output is correct
38 Correct 13 ms 8188 KB Output is correct
39 Correct 14 ms 8188 KB Output is correct
40 Correct 11 ms 8188 KB Output is correct
41 Correct 12 ms 8188 KB Output is correct
42 Correct 12 ms 8188 KB Output is correct
43 Correct 12 ms 8188 KB Output is correct
44 Correct 14 ms 8188 KB Output is correct
45 Correct 12 ms 8188 KB Output is correct
46 Correct 15 ms 8492 KB Output is correct
47 Correct 13 ms 8492 KB Output is correct
48 Correct 11 ms 8492 KB Output is correct
49 Correct 15 ms 8492 KB Output is correct
50 Correct 12 ms 8492 KB Output is correct
51 Correct 12 ms 8492 KB Output is correct
52 Correct 15 ms 8492 KB Output is correct
53 Correct 12 ms 8492 KB Output is correct
54 Correct 13 ms 8492 KB Output is correct
55 Correct 19 ms 8956 KB Output is correct
56 Correct 60 ms 12796 KB Output is correct
57 Correct 87 ms 16380 KB Output is correct
58 Correct 106 ms 18808 KB Output is correct
59 Correct 149 ms 22576 KB Output is correct
60 Correct 195 ms 26100 KB Output is correct
61 Correct 229 ms 28800 KB Output is correct
62 Correct 288 ms 30960 KB Output is correct
63 Correct 318 ms 35556 KB Output is correct
64 Correct 367 ms 36464 KB Output is correct
65 Correct 166 ms 36464 KB Output is correct
66 Correct 192 ms 36464 KB Output is correct
67 Correct 163 ms 36464 KB Output is correct
68 Correct 300 ms 36464 KB Output is correct
69 Correct 343 ms 36464 KB Output is correct
70 Correct 293 ms 36464 KB Output is correct
71 Correct 351 ms 55404 KB Output is correct
72 Correct 261 ms 55660 KB Output is correct
73 Correct 218 ms 55660 KB Output is correct
74 Correct 232 ms 55660 KB Output is correct
75 Correct 246 ms 55660 KB Output is correct
76 Correct 227 ms 55660 KB Output is correct
77 Correct 251 ms 55660 KB Output is correct
78 Correct 320 ms 55660 KB Output is correct
79 Correct 266 ms 55660 KB Output is correct