답안 #106301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
106301 2019-04-17T19:54:54 Z alexpetrescu Fireworks (APIO16_fireworks) C++14
26 / 100
20 ms 16896 KB
#include <cstdio>
#include <queue>
#include <algorithm>
#include <vector>

//FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w");
#define fin stdin
#define fout stdout

#define ll long long

#define MAXN 300000

std::vector < int > g[MAXN + 1];
ll d[MAXN + 1];
int c[MAXN + 1];
std::priority_queue < ll > q[MAXN + 1];

void dfs(int x) {
    for (auto &y : g[x]) {
        dfs(y);
        d[x] += d[y];
        while (!q[y].empty()) {
            q[x].push(q[y].top());
            q[y].pop();
        }
    }
    for (int i = g[x].size(); i > bool(c[x]); i--) {
        d[x] += q[x].top();
        q[x].pop();
    }
    if (g[x].empty()) {
        q[x].push(c[x]);
        q[x].push(c[x]);
        d[x] = -c[x];
    } else if (c[x]) {
        int a = q[x].top();
        q[x].pop();
        int b = q[x].top();
        q[x].pop();
        q[x].push(a + c[x]);
        q[x].push(b + c[x]);
        d[x] -= c[x];
    }
}

int main() {
    int n, m;
    fscanf(fin, "%d%d", &n, &m);
    n += m;

    for (int i = 2; i <= n; i++) {
        int x;
        fscanf(fin, "%d%d", &x, &c[i]);
        g[x].push_back(i);
    }

    dfs(1);

    fprintf(fout, "%lld\n", d[1]);

    fclose(fin);
    fclose(fout);
    return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:49:11: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     fscanf(fin, "%d%d", &n, &m);
     ~~~~~~^~~~~~~~~~~~~~~~~~~~~
fireworks.cpp:54:15: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         fscanf(fin, "%d%d", &x, &c[i]);
         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 16768 KB Output is correct
2 Correct 18 ms 16768 KB Output is correct
3 Correct 17 ms 16768 KB Output is correct
4 Correct 17 ms 16768 KB Output is correct
5 Correct 16 ms 16768 KB Output is correct
6 Correct 17 ms 16836 KB Output is correct
7 Correct 17 ms 16768 KB Output is correct
8 Correct 17 ms 16740 KB Output is correct
9 Correct 17 ms 16768 KB Output is correct
10 Correct 17 ms 16840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 16768 KB Output is correct
2 Correct 17 ms 16768 KB Output is correct
3 Correct 16 ms 16768 KB Output is correct
4 Correct 15 ms 16768 KB Output is correct
5 Correct 17 ms 16768 KB Output is correct
6 Correct 16 ms 16768 KB Output is correct
7 Correct 16 ms 16768 KB Output is correct
8 Correct 16 ms 16768 KB Output is correct
9 Correct 16 ms 16768 KB Output is correct
10 Correct 17 ms 16768 KB Output is correct
11 Correct 17 ms 16768 KB Output is correct
12 Correct 17 ms 16812 KB Output is correct
13 Correct 16 ms 16768 KB Output is correct
14 Correct 15 ms 16896 KB Output is correct
15 Correct 15 ms 16768 KB Output is correct
16 Correct 16 ms 16768 KB Output is correct
17 Correct 17 ms 16768 KB Output is correct
18 Correct 18 ms 16768 KB Output is correct
19 Correct 20 ms 16768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 16768 KB Output is correct
2 Correct 18 ms 16768 KB Output is correct
3 Correct 17 ms 16768 KB Output is correct
4 Correct 17 ms 16768 KB Output is correct
5 Correct 16 ms 16768 KB Output is correct
6 Correct 17 ms 16836 KB Output is correct
7 Correct 17 ms 16768 KB Output is correct
8 Correct 17 ms 16740 KB Output is correct
9 Correct 17 ms 16768 KB Output is correct
10 Correct 17 ms 16840 KB Output is correct
11 Correct 17 ms 16768 KB Output is correct
12 Correct 17 ms 16768 KB Output is correct
13 Correct 16 ms 16768 KB Output is correct
14 Correct 15 ms 16768 KB Output is correct
15 Correct 17 ms 16768 KB Output is correct
16 Correct 16 ms 16768 KB Output is correct
17 Correct 16 ms 16768 KB Output is correct
18 Correct 16 ms 16768 KB Output is correct
19 Correct 16 ms 16768 KB Output is correct
20 Correct 17 ms 16768 KB Output is correct
21 Correct 17 ms 16768 KB Output is correct
22 Correct 17 ms 16812 KB Output is correct
23 Correct 16 ms 16768 KB Output is correct
24 Correct 15 ms 16896 KB Output is correct
25 Correct 15 ms 16768 KB Output is correct
26 Correct 16 ms 16768 KB Output is correct
27 Correct 17 ms 16768 KB Output is correct
28 Correct 18 ms 16768 KB Output is correct
29 Correct 20 ms 16768 KB Output is correct
30 Incorrect 17 ms 16872 KB Output isn't correct
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 16768 KB Output is correct
2 Correct 18 ms 16768 KB Output is correct
3 Correct 17 ms 16768 KB Output is correct
4 Correct 17 ms 16768 KB Output is correct
5 Correct 16 ms 16768 KB Output is correct
6 Correct 17 ms 16836 KB Output is correct
7 Correct 17 ms 16768 KB Output is correct
8 Correct 17 ms 16740 KB Output is correct
9 Correct 17 ms 16768 KB Output is correct
10 Correct 17 ms 16840 KB Output is correct
11 Correct 17 ms 16768 KB Output is correct
12 Correct 17 ms 16768 KB Output is correct
13 Correct 16 ms 16768 KB Output is correct
14 Correct 15 ms 16768 KB Output is correct
15 Correct 17 ms 16768 KB Output is correct
16 Correct 16 ms 16768 KB Output is correct
17 Correct 16 ms 16768 KB Output is correct
18 Correct 16 ms 16768 KB Output is correct
19 Correct 16 ms 16768 KB Output is correct
20 Correct 17 ms 16768 KB Output is correct
21 Correct 17 ms 16768 KB Output is correct
22 Correct 17 ms 16812 KB Output is correct
23 Correct 16 ms 16768 KB Output is correct
24 Correct 15 ms 16896 KB Output is correct
25 Correct 15 ms 16768 KB Output is correct
26 Correct 16 ms 16768 KB Output is correct
27 Correct 17 ms 16768 KB Output is correct
28 Correct 18 ms 16768 KB Output is correct
29 Correct 20 ms 16768 KB Output is correct
30 Incorrect 17 ms 16872 KB Output isn't correct
31 Halted 0 ms 0 KB -