#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct segTree{
ll tree[400002];
void update(int i, int l, int r, int x, ll v){
if(l==r){
tree[i] = max(tree[i], v);
return;
}
int m = (l+r)>>1;
if(x<=m) update(i*2, l, m, x, v);
else update(i*2+1, m+1, r, x, v);
tree[i] = max(tree[i*2], tree[i*2+1]);
}
ll query(int i, int l, int r, int s, int e){
if(r<s || e<l) return 0;
if(s<=l && r<=e) return tree[i];
int m = (l+r)>>1;
return max(query(i*2, l, m, s, e), query(i*2+1, m+1, r, s, e));
}
} tree;
struct Fruit{
int v, d; ll w;
Fruit(){}
Fruit(int v, int d, ll w): v(v), d(d), w(w){}
};
int n, m, k;
int par[100002];
vector<int> child[100002];
int in[100002], out[100002], inCnt;
int state[100002];
Fruit fruit[100002];
void dfs(int x){
in[x] = ++inCnt;
for(auto y: child[x]) dfs(y);
out[x] = inCnt;
for(int i=in[x]; i<=out[x]; i++) state[x] |= (1<<i);
}
int main(){
scanf("%d %d %d", &n, &m, &k);
for(int i=2; i<=n; i++){
scanf("%d", &par[i]);
// par[i] = i-1;
child[par[i]].push_back(i);
}
for(int i=1; i<=m; i++){
int v, d, w;
scanf("%d %d %d", &v, &d, &w);
fruit[i] = Fruit(v, d, w);
}
dfs(1);
sort(fruit+1, fruit+m+1, [&](Fruit &a, Fruit &b){
if(a.d==b.d) return in[a.v]>in[b.v];
return a.d<b.d;
});
for(int i=1; i<=m; i++){
Fruit f = fruit[i];
tree.update(1, 1, n, f.v-1, tree.query(1, 1, n, f.v, n) + f.w);
}
printf("%lld", tree.query(1, 1, n, 1, n));
}
Compilation message
magictree.cpp: In function 'int main()':
magictree.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scanf("%d %d %d", &n, &m, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
magictree.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | scanf("%d", &par[i]);
| ~~~~~^~~~~~~~~~~~~~~
magictree.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf("%d %d %d", &v, &d, &w);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
42 ms |
8044 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2772 KB |
Output is correct |
2 |
Correct |
2 ms |
2772 KB |
Output is correct |
3 |
Correct |
3 ms |
2772 KB |
Output is correct |
4 |
Correct |
1860 ms |
15612 KB |
Output is correct |
5 |
Correct |
1778 ms |
17676 KB |
Output is correct |
6 |
Correct |
1795 ms |
17516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
80 ms |
9224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
3796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |