Submission #1128256

#TimeUsernameProblemLanguageResultExecution timeMemory
1128256VMaksimoski008Magic Tree (CEOI19_magictree)C++20
34 / 100
124 ms32504 KiB
#include <bits/stdc++.h> #define ar array //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; vector<int> G[maxn]; int d[maxn], w[maxn], n, m, k; ll dp[maxn][21]; void dfs(int u) { dp[u][d[u]] = w[u]; for(int v : G[u]) { dfs(v); for(int i=0; i<=20; i++) dp[u][i] += dp[v][i]; } for(int i=1; i<=20; i++) dp[u][i] = max(dp[u][i], dp[u][i-1]); } signed main() { cin >> n >> m >> k; for(int i=2; i<=n; i++) { int p; cin >> p; G[p].push_back(i); } for(int i=1; i<=m; i++) { int a, b, c; cin >> a >> b >> c; d[a] = b; w[a] = c; } dfs(1); cout << dp[1][20] << '\n'; return 0; }
#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...