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;
#define f first
#define s second
#define int long long
#define pii pair <int, int>
#define pb push_back
using namespace std;
const int N = 1e5+5;
int t,n,a[N],m,k,tim[N],val[N],va,ti;
int ans,mx,p,vert,mp[N],cnt,dp[N][1005];
vector <int> v[N],vv;
void dfs(int a, int p) {
for (int i = 0; i < v[a].size(); i++) {
int to = v[a][i];
if (to == p) continue;
dfs(to,a);
}
for (int i = 1; i <= mx; i++) {
int sum = 0;
int sum1 = 0;
for (int j = 0; j < v[a].size(); j++) {
int to = v[a][j]; if (to == p) continue;
sum += dp[to][i];
sum1 += dp[to][tim[a]];
}
if (tim[a] <= i)
dp[a][i] = max(sum, sum1 + val[a]);
else dp[a][i] = sum;
ans = max(ans, dp[a][i]);
}
}
main() {
std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>m>>k;
for (int i = 2; i <= n; i++){
cin>>p;
v[p].pb(i);
v[i].pb(p);
}
dfs(1,0);
for (int i = 1; i <= m; i++){
cin>>vert>>ti>>va;
vv.pb(ti);
tim[vert] = ti;
val[vert] = va;
}
sort(vv.begin(),vv.end());
for (int i = 0; i < vv.size(); i++) {
if (i == 0)cnt++; else if (vv[i] != vv[i - 1]) cnt++;
mp[vv[i]] = cnt;
}
for (int i = 1; i <= n; i++) {
tim[i] = mp[tim[i]];
mx = max(mx,tim[i]);
}
dfs(1,0);
cout<<ans<<"\n";
}
Compilation message (stderr)
magictree.cpp: In function 'void dfs(long long int, long long int)':
magictree.cpp:14:23: 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]
14 | for (int i = 0; i < v[a].size(); i++) {
| ~~^~~~~~~~~~~~~
magictree.cpp:22:27: 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]
22 | for (int j = 0; j < v[a].size(); j++) {
| ~~^~~~~~~~~~~~~
magictree.cpp: At global scope:
magictree.cpp:33:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
33 | main() {
| ^~~~
magictree.cpp: In function 'int main()':
magictree.cpp:49:23: 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]
49 | for (int i = 0; i < vv.size(); i++) {
| ~~^~~~~~~~~~~
# | 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... |