Submission #1128254

#TimeUsernameProblemLanguageResultExecution timeMemory
1128254VMaksimoski008Magic Tree (CEOI19_magictree)C++20
12 / 100
1104 ms802612 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][1005]; void dfs(int u) { dp[u][d[u]] = w[u]; for(int v : G[u]) { dfs(v); for(int i=0; i<=1001; i++) dp[u][i] += dp[v][i]; } for(int i=1; i<=1001; 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; } set<int> st; for(int i=1; i<=m; i++) st.insert(d[i]); vector<int> comp(st.begin(), st.end()); for(int i=1; i<=m; i++) d[i] = lower_bound(comp.begin(), comp.end(), d[i]) - comp.begin(); dfs(1); cout << dp[1][1001] << '\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...