# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
417287 | shenxy | Worst Reporter 4 (JOI21_worst_reporter4) | C++11 | 1296 ms | 196932 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 <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
int N, A[5001], H[5001];
long long C[5001], dptable[5001][5001];
vector<int> adjlist[5001];
long long dp(int v, int k) {
if (dptable[v][k] != -1) return dptable[v][k];
if (H[v] >= H[k]) {
long long a1 = 0, a2 = 0;
if (H[v] != H[k]) a1 += C[v];
for (int i: adjlist[v]) a1 += dp(i, k), a2 += dp(i, v);
return dptable[v][k] = min(a1, a2);
} else {
dptable[v][k] = C[v];
for (int i: adjlist[v]) dptable[v][k] += dp(i, k);
return dptable[v][k];
}
}
int main() {
memset(dptable, -1, sizeof dptable);
scanf("%d", &N);
for (int i = 1; i <= N; ++i) scanf("%d %d %lld", &A[i], &H[i], &C[i]);
for (int i = 2; i <= N; ++i) adjlist[A[i]].push_back(i);
long long bans = 1000000000000000000LL;
for (int i = 1; i <= N; ++i) bans = min(bans, dp(1, i));
printf("%lld", bans);
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... |