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;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define MP make_pair
const int N = 100500;
vector<int> g[N];
ll dp[N][30];
pair<int, int> fruit[N];
void dfs(int v){
dp[v][fruit[v].first] = fruit[v].second;
for (int u : g[v]){
dfs(u);
}
for (int t = 1; t <= 20; t++){
for (int u : g[v]){
dp[v][t] += *max_element(dp[u], dp[u] + t + 1);
}
}
}
void solve(){
int n, m, k;
cin >> n >> m >> k;
for (int i = 2; i <= n; i++){
int p;
cin >> p;
g[p].push_back(i);
}
for (int i = 0; i < m; i++){
int v, d, w;
cin >> v >> d >> w;
fruit[v] = MP(d, w);
}
dfs(1);
cout << *max_element(dp[1], dp[1] + 30) << endl;
}
int main() {
ios_base::sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
return 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... |