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>
#define ll long long
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 9;
int n, m, w[100002], d[100002], k;
vector<int>G[100002];
map<int, ll>aib[100002];
void dfs (int nod) {
for (auto it : G[nod]) {
dfs(it);
if (aib[nod].size() < aib[it].size())
swap(aib[nod], aib[it]);
for (auto it2 : aib[it])
aib[nod][it2.first] += it2.second;
}
if (w[nod]) {
aib[nod][d[nod]] += w[nod];
while (1) {
auto it = aib[nod].upper_bound(d[nod]);
if (it == aib[nod].end())
break;
if (it->second < w[nod])
aib[nod].erase(it);
else {
it->second -= w[nod];
break;
}
}
}
}
int main ()
{
ios_base::sync_with_stdio(false);
cin >> n >> m >> k;
for (int i = 2; i <= n; i++) {
int x;
cin >> x;
G[x].push_back(i);
}
for (int i = 1; i <= m; i++) {
int v;
cin >> v;
cin >> d[v] >> w[v];
}
dfs(1);
ll ans = 0;
for (auto it : aib[1])
ans += it.second;
cout << ans;
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... |