Submission #598443

#TimeUsernameProblemLanguageResultExecution timeMemory
598443AlesL0Magic Tree (CEOI19_magictree)C++17
0 / 100
2080 ms11336 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector <ll> val, w, d, dp; void dfs_getval(ll c, ll v, vector <ll> g[]){ if (v != c && d[c] == d[v])val[v] += w[c]; for (auto k : g[c])dfs_getval(k, v, g); } void dfs_dp(ll c, vector <ll> g[]){ ll sum = 0; for (auto k : g[c]){ dfs_dp(k, g); sum += dp[k]; } dp[c] = max(val[c], sum); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n, m, k; cin >> n >> m >> k; vector <ll> g[n+1]; val.resize(n+1, 0); w.resize(n+1, 0); d.resize(n+1, -1); dp.resize(n+1); for (int i = 2; i <= n; i++){ ll a; cin >> a; g[a].push_back(i); } while (m--){ ll a, b, c; cin >> a >> b >> c; w[a] = c; val[a] = c; d[a] = b; } for (int i = 1; i <= n; i++)dfs_getval(i, i, g); dfs_dp(1, g); cout << dp[1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...