# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
709735 | Ronin13 | Worst Reporter 4 (JOI21_worst_reporter4) | C++14 | 433 ms | 267692 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>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 5001;
vector <vector <int> > g(nmax);
vector <int> vec;
int a[nmax], h[nmax];
ll c[nmax];
ll dp[nmax][nmax];
void dfs(int v, int e){
for(int to : g[v]){
if(to == e) continue;
dfs(to, v);
}
for(int j = vec.size() - 1; j >= 0; j--){
ll C = 0;
if(vec[j] != h[v]){
C = c[v];
}
for(int to : g[v]){
if(to == e) continue;
C += dp[to][j];
}
if(j == vec.size() - 1)
dp[v][j] = C;
else
dp[v][j] = min(dp[v][j + 1], C);
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i] >> h[i] >> c[i];
g[a[i]].pb(i);
vec.pb(h[i]);
}
sort(vec.begin(), vec.end());
dfs(1, 1);
cout << dp[1][0];
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... |