#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);
}
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);
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);
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-1)<<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 |
12 ms |
6384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
6604 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 |
2136 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 |
- |