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;
#define ll long long
const int nx=1e5+5;
ll n, m, k, t[nx], w[nx], tmp[nx], x, p, sm, ans;
vector<int> d[nx];
struct value
{
ll time;
mutable ll val, idx;
bool operator< (const value &o) const
{
return time<o.time;
}
};
multiset<value> ms[nx];
void dfs(int u)
{
for (auto v:d[u]) dfs(v);
for (auto v:d[u]) for (auto tmp:ms[v]) ms[u].insert(tmp);
for (auto v:d[u]) ms[v].clear();
sm=0;
for (auto itr=ms[u].begin(); itr!=ms[u].end(); itr++)
{
sm+=itr->val-tmp[itr->idx];
tmp[itr->idx]=itr->val;
itr->val=sm;
itr->idx=u;
}
if (!t[u]) {
for (auto vl:ms[u]) ans=max(ans, vl.val);
return;
}
value nw;
nw.time=t[u]; nw.val=w[u]; nw.idx=u;
auto itr=ms[u].upper_bound(nw);
if (itr!=ms[u].begin()) nw.val+=prev(itr)->val;
itr=ms[u].insert(nw);
while (next(itr)!=ms[u].end()&&next(itr)->val<=itr->val) ms[u].erase(next(itr));
for (auto vl:ms[u]) ans=max(ans, vl.val);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m>>k;
for (int i=2; i<=n; i++) cin>>p, d[p].push_back(i);
for (int i=1; i<=m; i++) cin>>x>>t[x]>>w[x];
dfs(1);
cout<<ans<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |