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 int long long
const int INF = 1e18;
const int maxn = 1e5;
int n,m,k;
int parent[maxn+5];
int w[maxn+5];
int day[maxn+5];
vector<int> con[maxn+5];
vector<pair<int,int>> rez[maxn+5];///{zi,suc}
int getrez(int nod, int zi)
{
if(rez[nod].empty())
return 0;
pair<int,int> aux = {zi,INF};
auto it = lower_bound(rez[nod].begin(),rez[nod].end(),aux);
if(it==rez[nod].begin())
return 0;
it--;
pair<int,int> cop = *it;
return cop.second;
}
void dfs(int nod)
{
map<int,int> calc;
for(auto adj:con[nod])
{
dfs(adj);
for(auto x:rez[adj])
calc[x.first]++;
}
if(day[nod]!=0) calc[day[nod]]++;
int mxm=0;
for(auto it:calc)
{
pair<int,int> aux = {it.first, 0};
if(aux.first == day[nod])
aux.second += w[nod];
for(auto adj:con[nod])
{
aux.second += getrez(adj, aux.first);
}
if(aux.second > mxm)
{
mxm = aux.second;
rez[nod].push_back(aux);
}
}
}
signed main()
{
cin>>n>>m>>k;
for(int i=2;i<=n;i++)
{
cin>>parent[i];
con[parent[i]].push_back(i);
}
int a;
for(int i=1;i<=m;i++)
{
cin>>a;
cin>>day[a]>>w[a];
}
dfs(1);
cout<<rez[1].back().second;
return 0;
}
/**
*/
# | 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... |