/**
* author: wxhtzdy
* created: 22.08.2023 09:39:57
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<vector<int>> g(n);
for (int i = 1; i < n; i++) {
int p;
cin >> p;
--p;
g[p].push_back(i);
}
vector<int> x(n, -1), y(n);
for (int i = 0; i < m; i++) {
int v, d, w;
cin >> v >> d >> w;
--v;
x[v] = d;
y[v] = w;
}
vector<vector<long long>> dp(n);
vector<vector<int>> days(n);
vector<int> f(n);
/* auto Insert = [&](int v, int d, int val) {
long long s = 0;
for (auto& p : dp[f[v]]) {
if (p.first < d) {
s += p.first;
if (s > val) {
break;
}
} else {
break;
}
}
if (s <= val) {
while (!dp[f[v]].empty() && dp[f[v]].begin()->first < d) {
dp[f[v]].erase(dp[f[v]].begin());
}
dp[f[v]].emplace(d, val);
}
}; */
function<void(int)> Solve = [&](int v) {
for (int u : g[v]) {
Solve(u);
for (int x : days[u]) {
days[v].push_back(x);
}
}
if (x[v] != -1) {
days[v].push_back(x[v]);
}
sort(days[v].begin(), days[v].end());
days[v].erase(unique(days[v].begin(), days[v].end()), days[v].end());
int sz = (int) days[v].size();
dp[v].resize(sz);
for (int u : g[v]) {
long long mx = 0;
int ptr = 0;
for (int j = 0; j < sz; j++) {
while (ptr < (int) days[u].size() && days[v][j] >= days[u][ptr]) {
mx = max(mx, dp[u][ptr]);
ptr += 1;
}
dp[v][j] += mx;
}
}
if (x[v] != -1) {
for (int i = 0; i < sz; i++) {
if (days[v][i] == x[v]) {
dp[v][i] += y[v];
break;
}
}
}
};
Solve(0);
cout << *max_element(dp[0].begin(), dp[0].end()) << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
16516 KB |
Output is correct |
2 |
Runtime error |
1889 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
3156 KB |
Output is correct |
2 |
Correct |
5 ms |
3412 KB |
Output is correct |
3 |
Correct |
4 ms |
3156 KB |
Output is correct |
4 |
Execution timed out |
2097 ms |
419828 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
16324 KB |
Output is correct |
2 |
Correct |
82 ms |
16256 KB |
Output is correct |
3 |
Correct |
69 ms |
21572 KB |
Output is correct |
4 |
Correct |
42 ms |
14868 KB |
Output is correct |
5 |
Correct |
51 ms |
28856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
64 ms |
18232 KB |
Output is correct |
11 |
Correct |
61 ms |
17552 KB |
Output is correct |
12 |
Correct |
87 ms |
41576 KB |
Output is correct |
13 |
Correct |
34 ms |
14796 KB |
Output is correct |
14 |
Correct |
86 ms |
53820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2644 KB |
Output is correct |
2 |
Correct |
24 ms |
10912 KB |
Output is correct |
3 |
Correct |
21 ms |
10956 KB |
Output is correct |
4 |
Correct |
22 ms |
11056 KB |
Output is correct |
5 |
Correct |
73 ms |
9172 KB |
Output is correct |
6 |
Correct |
166 ms |
108160 KB |
Output is correct |
7 |
Correct |
466 ms |
259036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
8 ms |
3156 KB |
Output is correct |
11 |
Correct |
5 ms |
3412 KB |
Output is correct |
12 |
Correct |
4 ms |
3156 KB |
Output is correct |
13 |
Execution timed out |
2097 ms |
419828 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
54 ms |
16516 KB |
Output is correct |
11 |
Runtime error |
1889 ms |
1048576 KB |
Execution killed with signal 9 |
12 |
Halted |
0 ms |
0 KB |
- |