# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242391 | tqbfjotld | Magic Tree (CEOI19_magictree) | C++14 | 191 ms | 29048 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;
#define int long long
bool fruit[100005];
int day[100005];
int val[100005];
vector<int> adjl[100005];
int n,m,k;
map<int,int> func(int node){
map<int,int> ans;
if (adjl[node].size()>=1){
ans = func(adjl[node][0]);
}
for (int x = 1; x<adjl[node].size(); x++){
int ch = adjl[node][x];
auto res = func(ch);
if (res.size()>ans.size()){
swap(res,ans);
}
for (auto item : res){
ans[item.first] += item.second;
}
}
if (fruit[node]){
ans[day[node]] += val[node];
int t = val[node];
auto it = ans.upper_bound(day[node]);
while (t>0&& it!=ans.end()){
if ((*it).second<=t){
t -= (*it).second;
it = ans.erase(it);
}
else{
ans[(*it).first] -= t;
break;
}
}
}
return ans;
}
main(){
scanf("%lld%lld%lld",&n,&m,&k);
for (int x = 1; x<n; x++){
int t;
scanf("%lld",&t);
t--;
adjl[t].push_back(x);
}
for (int x = 0; x<m; x++){
int a,b;
long long c;
scanf("%lld%lld%lld",&a,&b,&c);
a--;
fruit[a] = true;
day[a] = b;
val[a] = c;
}
auto res = func(0);
long long ans = 0;
for (auto x : res){
ans += x.second;
}
printf("%lld",ans);
}
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... |
# | 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... |