This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<int , x>
#define endl '\n'\
int n , m , k;
vector<int> tr[100000];
ll frt[100000][2] , dp[100000][2];
void dfs(int v = 0){
dp[v][1] = frt[v][1];
for(int u : tr[v]){
dfs(u);
dp[v][0] += max(dp[u][0] , dp[u][1]);
if(frt[v][0] >= frt[u][0]) dp[v][1] += max(dp[u][0] , dp[u][1]);
else dp[v][1] += dp[u][0];
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> k;
for(int i = 1 ; i < n ; i++){
int d;
cin >> d;
tr[d - 1].pb(i);
}
for(int i = 0 ; i < m ; i++){
int v;
cin >> v;
cin >> frt[v - 1][0] >> frt[v - 1][1];
}
dfs();
cout << dp[0][0];
}
# | 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... |