Submission #967980

# Submission time Handle Problem Language Result Execution time Memory
967980 2024-04-23T06:27:13 Z TAhmed33 Fireworks (APIO16_fireworks) C++
0 / 100
3 ms 7516 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 3e5 + 25;
vector <pair <int, int>> adj[MAXN];
int dp[MAXN], n, m;
void dfs (int pos) {
    for (auto j : adj[pos]) {
        dfs(j.first);
    }
    dp[pos] = 1e18;
    for (int i = 0; i <= 300; i++) {
        int sum = 0;
        for (auto j : adj[pos]) {
            sum += abs(i - j.second) + dp[j.first];
        }
        dp[pos] = min(dp[pos], sum);
    }
}
signed main () {
    cin >> n >> m;
    n += m;
    for (int i = 2; i <= n; i++) {
        int x, y; cin >> x >> y;
        adj[x].push_back({i, y});
    }
    dfs(1);
    cout << dp[1];
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7516 KB Output isn't correct
2 Halted 0 ms 0 KB -