답안 #682447

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682447 2023-01-16T08:58:55 Z stevancv Fireworks (APIO16_fireworks) C++14
7 / 100
7 ms 9744 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 3e5 + 2;
const ll linf = 9e18;
priority_queue<ll> pq[N];
int deg[N], par[N];
ll len[N], dp[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 2; i <= n + m; i++) {
        cin >> par[i] >> len[i];
        deg[par[i]]++;
        dp[par[i]] -= len[i];
        if (i > n) {
            pq[par[i]].push(len[i]);
            pq[par[i]].push(len[i]);
        }
    }
    for (int i = n; i > 1; i--) {
        for (int j = 0; j < deg[i] - 1; j++) {
            dp[i] += pq[i].top();
            pq[i].pop();
        }
        pq[par[i]].push(pq[i].top() + len[i]);
        pq[i].pop();
        pq[par[i]].push(pq[i].top() + len[i]);
        pq[i].pop();
        dp[par[i]] += dp[i];
    }
    ll ans = 0;
    for (int j = 0; j < deg[1]; j++) {
        ans += pq[1].top();
        pq[1].pop();
    }
    cout << dp[1] + ans << en;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9724 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9744 KB Output is correct
4 Correct 7 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9724 KB Output is correct
8 Correct 6 ms 9720 KB Output is correct
9 Correct 6 ms 9696 KB Output is correct
10 Correct 5 ms 9724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Incorrect 5 ms 9724 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9724 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9744 KB Output is correct
4 Correct 7 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9724 KB Output is correct
8 Correct 6 ms 9720 KB Output is correct
9 Correct 6 ms 9696 KB Output is correct
10 Correct 5 ms 9724 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Incorrect 5 ms 9724 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9724 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9744 KB Output is correct
4 Correct 7 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9724 KB Output is correct
8 Correct 6 ms 9720 KB Output is correct
9 Correct 6 ms 9696 KB Output is correct
10 Correct 5 ms 9724 KB Output is correct
11 Correct 5 ms 9684 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Incorrect 5 ms 9724 KB Output isn't correct
14 Halted 0 ms 0 KB -