# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1093142 | 12345678 | Worst Reporter 4 (JOI21_worst_reporter4) | C++17 | 294 ms | 119344 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 nx=2e5+5;
#define ll long long
ll n, pa[nx], h[nx], c[nx];
vector<ll> d[nx];
map<ll, ll> mp[nx];
void dfs(int u)
{
mp[u][0]=c[u];
for (auto v:d[u])
{
dfs(v);
if (mp[v].size()>mp[u].size()) swap(mp[u], mp[v]);
for (auto [x, y]:mp[v]) mp[u][x]+=y;
}
mp[u][h[u]]+=0;
mp[u][h[u]+1]+=c[u];
auto itr=mp[u].find(h[u]);
ll sm=-c[u], lst=h[u];
while (1)
{
sm+=itr->second;
if (sm>=0) break;
itr=mp[u].erase(itr);
itr--;
}
mp[u][itr->first]=sm;
//cout<<"debug "<<u<<'\n';
//cout<<"mp ";
//for (auto x:mp[u]) cout<<x.first<<' '<<x.second<<'\n';
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>pa[i]>>h[i]>>c[i];
for (int i=2; i<=n; i++) d[pa[i]].push_back(i);
dfs(1);
cout<<mp[1].begin()->second;
}
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... |