# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
242521 | dantoh000 | Magic Tree (CEOI19_magictree) | C++14 | 182 ms | 36984 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 pair<int,int> ii;
typedef long long ll;
int n,m,k;
vector<int> G[100005];
ii V[100005];
map<int,ll> dp[100005];
void dfs(int u){
auto& cur = dp[u];
for (auto v: G[u]){
dfs(v);
if (dp[v].size() > cur.size()){
swap(dp[v],cur);
}
for (auto x : dp[v]){
cur[x.first] += x.second;
}
}
if (V[u] == ii(0,0)) return;
cur[V[u].first] += V[u].second;
int bad = V[u].second;
auto it = cur.find(V[u].first);
it++;
while (it != cur.end()){
if (it->second < bad){
bad -= it->second;
it = cur.erase(it);
}
else{
it->second -= bad;
break;
}
}
return;
}
int main(){
scanf("%d%d%d",&n,&m,&k);
for (int i = 2,p; i <= n; i++){
scanf("%d",&p);
G[p].push_back(i);
}
for (int i = 0; i < m; i++){
int v,d,w;
scanf("%d%d%d",&v,&d,&w);
V[v] = ii(d,w);
}
dfs(1);
ll ans = 0;
for (auto x : dp[1]) ans += x.second;
printf("%lld\n",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... |