# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
198650 | arnold518 | Magic Tree (CEOI19_magictree) | C++14 | 206 ms | 34552 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 long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
int N, MM, K, D[MAXN+10], W[MAXN+10];
vector<int> adj[MAXN+10];
map<int, ll> M[MAXN+10];
void dfs(int now)
{
for(int nxt : adj[now])
{
dfs(nxt);
if(M[now].size()<M[nxt].size()) swap(M[now], M[nxt]);
for(auto it : M[nxt]) M[now][it.first]+=it.second;
}
if(D[now])
{
vector<map<int, ll>::iterator> V;
ll s=0;
auto it=M[now].upper_bound(D[now]);
for(; it!=M[now].end(); it++)
{
s+=it->second;
if(W[now]<s) break;
V.push_back(it);
}
if(it!=M[now].end()) it->second=s-W[now];
for(auto jt : V) M[now].erase(jt);
M[now][D[now]]+=W[now];
}
}
int main()
{
int i, j;
scanf("%d%d%d", &N, &MM, &K);
for(i=2; i<=N; i++)
{
int u;
scanf("%d", &u);
adj[u].push_back(i);
}
for(i=1; i<=MM; i++)
{
int v, d, w;
scanf("%d%d%d", &v, &d, &w);
D[v]=d; W[v]=w;
}
dfs(1);
ll ans=0;
for(auto it : M[1]) ans+=it.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... |