# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
398727 | ChrisT | Worst Reporter 4 (JOI21_worst_reporter4) | C++17 | 231 ms | 201444 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;
const int MN = 2e5 + 5, SUB = 5e3 + 1;
int a[MN], h[MN], c[MN];
long long dp[SUB][SUB];
vector<int> adj[MN], xs;
int getx (int x) {return lower_bound(xs.begin(),xs.end(),x) - xs.begin() + 1;}
void dfs (int cur) {
for (int i : adj[cur]) {
dfs(i);
for (int j = 1; j <= (int)xs.size(); j++) dp[cur][j] += dp[i][j];
}
for (int j = 1; j <= (int)xs.size(); j++) dp[cur][j] += c[cur];
dp[cur][h[cur]] -= c[cur];
for (int j = (int)xs.size()-1; j >= 1; j--) dp[cur][j] = min(dp[cur][j],dp[cur][j+1]);
}
int main () {
int n; scanf ("%d",&n);
for (int i = 1; i <= n; i++) {
scanf ("%d %d %d",&a[i],&h[i],&c[i]);
xs.push_back(h[i]);
if (i > 1) adj[a[i]].push_back(i);
}
sort(xs.begin(),xs.end()); xs.erase(unique(xs.begin(),xs.end()),xs.end());
for (int i = 1; i <= n; i++) h[i] = getx(h[i]);
dfs(1);
long long ret = 1e18;
for (int i = 1; i <= (int)xs.size(); i++) ret = min(ret,dp[1][i]);
printf ("%lld\n",ret);
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... |