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;
int n, m, k, par[101010];
pii arr[101010];
vector<int> adj[101010];
ll ans = 0;
struct maxseg {
ll tree[404040];
void init(int v, int st, int ed) {
if (st == ed) {
tree[v] = 0;
return;
}
int mid = (st + ed) / 2;
init(2 * v, st, mid);
init(2 * v + 1, mid + 1, ed);
}
void update(int v, int st, int ed, int idx, ll val) {
if (st == idx && ed == idx) {
tree[v] = val;
return;
}
if (st > idx || ed < idx) return;
int mid = (st + ed) / 2;
update(2 * v, st, mid, idx, val);
update(2 * v + 1, mid + 1, ed, idx, val);
tree[v] = max(tree[2 * v], tree[2 * v + 1]);
}
ll get(int v, int st, int ed, int lt, int rt) {
if (lt <= st && ed <= rt) return tree[v];
if (lt > ed || st > rt) return 0;
int mid = (st + ed) / 2;
return max(get(2 * v, st, mid, lt, rt), get(2 * v + 1, mid + 1, ed, lt, rt));
}
} seg;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 2; i <= n; i++) {
cin >> par[i];
adj[par[i]].push_back(i);
}
for (int i = 1; i <= m; i++) {
int v, d, w;
cin >> v >> d >> w;
arr[v] = {d, w};
}
seg.init(1, 1, k);
for(int i = n; i >= 1; i--) {
if (arr[i].second == 0) continue;
ll val = seg.get(1, 1, k, 1, arr[i].first) + arr[i].second;
ans = max(ans, val);
seg.update(1, 1, k, arr[i].first, val);
}
cout << ans << "\n";
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... |