답안 #166381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
166381 2019-12-02T03:08:47 Z abcdef6199 Fireworks (APIO16_fireworks) C++
0 / 100
9 ms 376 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> II;

const int MAXN = 300 + 10;
int n, m;
vector<II> adj[MAXN];

int dp[MAXN][MAXN];

void dfs(int u) {
    if (adj[u].size() == 0) {
        for (int i = 1; i <= 300; ++i) {
            dp[u][i] = (int)1e9;
        }
        dp[u][0] = 0;
        return;
    }

    dp[u][0] = (int)1e9;
    for (int i = 0; i < (int)adj[u].size(); ++i) {
        int v = adj[u][i].first;
        int w = adj[u][i].second;
        dfs(v);

        for (int x = 1; x <= 300; ++x) {
            int t = (int)1e9;
            for (int y = 0; y <= 300; ++y) {
                int d = x - y;
                t = min(t, dp[v][y] + abs(d - w));
            }
            dp[u][x] += t;
        }
    }
}

int main() {
    scanf("%d%d", &n, &m);
    n += m;
    for (int i = 2; i <= n; ++i) {
        int p, w;
        scanf("%d%d", &p, &w);
        adj[p].push_back(II(i, w));
    }

    dfs(1);
    printf("%d\n", *min_element(dp[1] + 1, dp[1] + 1 + 300));
    return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:40: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:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &p, &w);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 7 ms 376 KB Output is correct
3 Incorrect 9 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -