#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 305;
const ll inf = 2e18;
vector<array<int, 2>> adj[N];
ll dp[N][N];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
n += m;
for (int i = 2; i <= n; i++) {
int p, c;
cin >> p >> c;
adj[p].push_back({i, c});
}
for (int i = n; i >= 1; i--) {
for (int j = 0; j < N; j++) {
for (auto [nxt, w] : adj[i]) {
ll mn = 1e18;
for (int k = 0; k <= j; k++) {
mn = min(mn, dp[i][j - k] + abs(k - w));
}
dp[i][j] += mn;
dp[i][j] = min(dp[i][j], inf);
}
}
}
cout << *min_element(dp[1], dp[1] + N) << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |