Submission #900514

#TimeUsernameProblemLanguageResultExecution timeMemory
900514Trisanu_DasMagic Tree (CEOI19_magictree)C++17
100 / 100
116 ms37804 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int N, M, K, res = 0, u; cin >> N >> M >> K; vector<int> g[N]; int d[N] {}, w[N] {}; map<int, int> dp[N]; for (int i = 1; i < N; i++) { cin >> u; g[u - 1].push_back(i); } while (M--) { cin >> u >> d[u - 1] >> w[u - 1]; } for (u = N; --u >= 0;) { int h = 0; for (int v : g[u]) if (dp[v].size() > dp[h].size()) h = v; dp[h].swap(dp[u]); for (int v : g[u]) if (v != h) for (auto &[i, j] : dp[v]) dp[u][i] += j; dp[u][d[u]] += w[u]; auto f = dp[u].upper_bound(d[u]); while (f != end(dp[u]) && (f->second -= w[u]) < 0) w[u] = -f->second, f = dp[u].erase(f); } for (auto &[i, j] : dp[0]) res += j; cout << res; }
#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...