#include<bits/stdc++.h>
using namespace std;
#define int long long
int N, M, K;
struct Fruit{
int pos = -1, t, w;
Fruit(){};
Fruit(int _pos, int _t, int _w){
pos = _pos;
t= _t;
w =_w;
}
};
struct SegTree{
int len = 1;
vector<int> tr;
SegTree(){};
SegTree(int n){
while(len<n){
len *= 2;
}
tr.resize(2*len,0);
}
void upd(int u){
for(u/=2; u>=1; u/=2){
tr[u] = max(tr[u*2], tr[u*2+1]);
}
}
int get(int l, int r){
l+=len;
r+=len+1;
int res= 0;
for(; l<r; l/=2, r/=2){
if(l%2 == 1){
res = max(res, tr[l++]);
}
if(r%2 == 1){
res = max(res, tr[--r]);
}
}
return res;
}
void set(int pos, int v){
tr[pos+len] = v;
upd(pos+len);
}
};
vector<Fruit> fr;
vector<Fruit> vertex_fruit;
vector<int> anc;
signed main(){
cin.tie(NULL);
ios_base::sync_with_stdio(false);
cin>>N>>M>>K;
vertex_fruit.resize(N, Fruit(-1, -1, -1));
anc.resize(N);
for(int i= 1; i<N; i++){
cin>>anc[i];
anc[i]--;
}
int RES =0;
for(int i = 0; i<M; i++){
int v, d, w;
cin>>v>>d>>w;
v--;
fr.push_back(Fruit(v, d, w));
vertex_fruit[v]= fr.back();
}
SegTree tr(K+1);
for(int i = N-1; i>=0; i--){
if(vertex_fruit[i].pos != -1){
int dp = tr.get(0, vertex_fruit[i].t) +1;
tr.set(vertex_fruit[i].t, dp);
}
}
cout<<tr.get(0, K)<<endl;
}
Compilation message
magictree.cpp: In function 'int main()':
magictree.cpp:75:9: warning: unused variable 'RES' [-Wunused-variable]
75 | int RES =0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
6352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
27 ms |
10232 KB |
Output is correct |
5 |
Correct |
26 ms |
10440 KB |
Output is correct |
6 |
Correct |
33 ms |
9932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
20 ms |
8144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |