#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,k,p[100005],i,u,w,d,sum,c;
vector<ll> v[100005],de;
pair<ll,ll> fruit[100005];
vector<vector<ll>> a;
map<ll,ll> mp;
map<ll,ll> ::iterator it;
multiset<ll> s;
multiset<ll> ::iterator is;
bool ar;
void dfs(ll x){
ll d=fruit[x].first;
ll w=fruit[x].second;
d=mp[d];
a[x][d]=w;
for(int i:v[x]){
dfs(i);
for(int j=1;j<=k;j++){
a[x][j]+=a[i][j];
}
}
for(int i=2;i<=k;i++) a[x][i]=max(a[x][i-1],a[x][i]);
}
int main(){
cin >> n >> m >> k;
ar=true;
for(i=2;i<=n;i++){
cin >> p[i];
if(i-1!=p[i]) ar=false;
v[p[i]].push_back(i);
}
for(i=1;i<=m;i++){
cin >> u >> d >> w;
mp[d]=1;
fruit[u]={d,w};
sum+=w;
c++;
de.push_back(d);
}
if(ar==true){
reverse(de.begin(),de.end());
for(i=0;i<de.size();i++){
is=s.upper_bound(de[i]);
if(is!=s.end()) s.erase(is);
s.insert(de[i]);
}
cout << s.size();
return 0;
}
k=0;
for(it=mp.begin();it!=mp.end();it++){
k++;
mp[it->first]=k;
}
if(k>1000){
cout << sum;
return 0;
}
a=vector<vector<ll>> (n+1,vector<ll> (k+1,0));
dfs(1);
cout << a[1][k];
}
Compilation message
magictree.cpp: In function 'int main()':
magictree.cpp:44:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(i=0;i<de.size();i++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4464 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4544 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
9516 KB |
Output is correct |
2 |
Correct |
43 ms |
9676 KB |
Output is correct |
3 |
Correct |
126 ms |
13216 KB |
Output is correct |
4 |
Correct |
98 ms |
12228 KB |
Output is correct |
5 |
Correct |
108 ms |
12908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
3 ms |
4632 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
91 ms |
14796 KB |
Output is correct |
5 |
Correct |
117 ms |
19372 KB |
Output is correct |
6 |
Correct |
115 ms |
15140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
15180 KB |
Output is correct |
2 |
Correct |
96 ms |
15048 KB |
Output is correct |
3 |
Correct |
90 ms |
18888 KB |
Output is correct |
4 |
Correct |
71 ms |
13620 KB |
Output is correct |
5 |
Incorrect |
95 ms |
13000 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4464 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4544 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
106 ms |
28592 KB |
Output is correct |
11 |
Correct |
95 ms |
20856 KB |
Output is correct |
12 |
Correct |
101 ms |
32464 KB |
Output is correct |
13 |
Correct |
79 ms |
27120 KB |
Output is correct |
14 |
Correct |
78 ms |
10568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
129620 KB |
Output is correct |
2 |
Correct |
665 ms |
607848 KB |
Output is correct |
3 |
Correct |
601 ms |
611156 KB |
Output is correct |
4 |
Correct |
748 ms |
789844 KB |
Output is correct |
5 |
Correct |
696 ms |
788164 KB |
Output is correct |
6 |
Correct |
764 ms |
792404 KB |
Output is correct |
7 |
Correct |
732 ms |
795036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4464 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4544 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4444 KB |
Output is correct |
11 |
Correct |
3 ms |
4632 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
91 ms |
14796 KB |
Output is correct |
14 |
Correct |
117 ms |
19372 KB |
Output is correct |
15 |
Correct |
115 ms |
15140 KB |
Output is correct |
16 |
Correct |
106 ms |
28592 KB |
Output is correct |
17 |
Correct |
95 ms |
20856 KB |
Output is correct |
18 |
Correct |
101 ms |
32464 KB |
Output is correct |
19 |
Correct |
79 ms |
27120 KB |
Output is correct |
20 |
Correct |
78 ms |
10568 KB |
Output is correct |
21 |
Incorrect |
15 ms |
5724 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4464 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4544 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
49 ms |
9516 KB |
Output is correct |
11 |
Correct |
43 ms |
9676 KB |
Output is correct |
12 |
Correct |
126 ms |
13216 KB |
Output is correct |
13 |
Correct |
98 ms |
12228 KB |
Output is correct |
14 |
Correct |
108 ms |
12908 KB |
Output is correct |
15 |
Correct |
2 ms |
4444 KB |
Output is correct |
16 |
Correct |
3 ms |
4632 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
91 ms |
14796 KB |
Output is correct |
19 |
Correct |
117 ms |
19372 KB |
Output is correct |
20 |
Correct |
115 ms |
15140 KB |
Output is correct |
21 |
Correct |
91 ms |
15180 KB |
Output is correct |
22 |
Correct |
96 ms |
15048 KB |
Output is correct |
23 |
Correct |
90 ms |
18888 KB |
Output is correct |
24 |
Correct |
71 ms |
13620 KB |
Output is correct |
25 |
Incorrect |
95 ms |
13000 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |