# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
932479 | andrei_boaca | Worst Reporter 4 (JOI21_worst_reporter4) | C++17 | 198 ms | 206684 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;
const ll INF=1e17;
map<ll,ll> nrm;
ll nr;
vector<ll> muchii[200005];
ll n,par[200005],v[200005],cost[200005];
ll dp[5005][5005];
void dfs(ll nod)
{
for(ll i:muchii[nod])
{
dfs(i);
ll minim=INF;
for(int j=nr;j>=1;j--)
{
minim=min(minim,dp[i][j]);
dp[nod][j]+=minim;
}
}
for(int i=1;i<=nr;i++)
if(i!=v[nod])
dp[nod][i]+=cost[nod];
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
vector<ll> vals;
for(int i=1;i<=n;i++)
{
cin>>par[i]>>v[i]>>cost[i];
if(i!=1)
muchii[par[i]].push_back(i);
vals.push_back(v[i]);
}
sort(vals.begin(),vals.end());
vals.erase(unique(vals.begin(),vals.end()),vals.end());
for(int i=0;i<vals.size();i++)
nrm[vals[i]]=i+1;
nr=vals.size();
for(int i=1;i<=n;i++)
v[i]=nrm[v[i]];
dfs(1);
ll ans=INF;
for(ll i=1;i<=nr;i++)
ans=min(ans,dp[1][i]);
cout<<ans;
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... |