#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100100;
int n, m, k;
int p[N];
int d[N];
int w[N];
map<int, ll> mp[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 2; i <= n; i++) {
cin >> p[i];
}
for (int i = 0; i < m; i++) {
int v;
cin >> v;
cin >> d[v] >> w[v];
}
auto merge = [&](int u, int v) {
if ((int)mp[u].size() < (int)mp[v].size()) swap(mp[u], mp[v]);
for (auto c : mp[v])
mp[u][c.first] += c.second;
};
for (int v = n; v >= 1; v--) {
auto it = mp[v].lower_bound(d[v]);
int s = w[v];
while (it != mp[v].end()) {
if (it->second <= s) {
s -= it->second;
mp[v].erase(it);
} else {
mp[v][it->first] = it->second - s;
break;
}
it = mp[v].lower_bound(d[v]);
}
mp[v][d[v]] += w[v];
merge(p[v], v);
}
ll s = 0;
for (auto c : mp[0])
s += c.second;
cout << s << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4952 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
19708 KB |
Output is correct |
2 |
Correct |
24 ms |
9808 KB |
Output is correct |
3 |
Correct |
115 ms |
40276 KB |
Output is correct |
4 |
Correct |
55 ms |
18260 KB |
Output is correct |
5 |
Correct |
79 ms |
22864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
37 ms |
12112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4952 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6236 KB |
Output is correct |
2 |
Correct |
16 ms |
10232 KB |
Output is correct |
3 |
Correct |
16 ms |
10156 KB |
Output is correct |
4 |
Correct |
17 ms |
10076 KB |
Output is correct |
5 |
Correct |
13 ms |
12636 KB |
Output is correct |
6 |
Correct |
17 ms |
10588 KB |
Output is correct |
7 |
Correct |
15 ms |
8028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4952 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Incorrect |
1 ms |
4952 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |