# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
45146 | erdemkiraz | Fireworks (APIO16_fireworks) | C++11 | 352 ms | 1640 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair < int, int > ii;
const int N = 600 + 5;
int n, m;
vector < ii > v[N];
int dp[N][N], dp2[N];
void dfs(int x) {
for(auto u : v[x])
dfs(u.first);
if(x > n) {
for(int i = 1; i < N; i++)
dp[x][i] = 1e9;
return;
}
for(auto u : v[x]) {
for(int i = 0; i < N; i++)
dp2[i] = 1e9;
for(int i = 0; i < N; i++)
for(int j = -N; j < N; j++)
if(u.second + j >= 0 and i + j + u.second < N)
dp2[i + j + u.second] = min(dp2[i + j + u.second], dp[u.first][i] + abs(j));
for(int i = 0; i < N; i++)
dp[x][i] += dp2[i];
}
}
int main() {
scanf("%d %d", &n, &m);
for(int i = 2; i <= n + m; i++) {
int x, c;
scanf("%d %d", &x, &c);
v[x].push_back({i, c});
}
dfs(1);
int res = 1e9;
for(int i = 0; i <= 600; i++) {
res = min(res, dp[1][i]);
}
printf("%d\n", res);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |