Submission #981711

#TimeUsernameProblemLanguageResultExecution timeMemory
981711duckindogMagic Tree (CEOI19_magictree)C++17
100 / 100
122 ms40632 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100'000 + 10; int n, m, k; vector<int> ad[N]; int d[N], w[N]; map<int, long long> f[N]; void merge(auto& x, auto& y) { if (x.size() < y.size()) swap(x, y); for (const auto& it : y) x[it.first] += it.second; } void dfs(int u, int p = 0) { for (const auto& v : ad[u]) { if (v == p) continue; dfs(v, u); merge(f[u], f[v]); } long long sum = w[u]; auto it = f[u].lower_bound(d[u] + 1); while (it != f[u].end()) { if (sum > it->second) { sum -= it->second; f[u].erase(it); } else { it->second -= sum; break; } it = f[u].lower_bound(d[u] + 1); } f[u][d[u]] += w[u]; } int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m >> k; for (int i = 2; i <= n; ++i) { int v; cin >> v; ad[i].push_back(v); ad[v].push_back(i); } for (int i = 1; i <= m; ++i) { int v; cin >> v >> d[v] >> w[v]; } dfs(1); long long answer = 0; for (const auto& x : f[1]) answer += x.second; cout << answer << "\n"; }

Compilation message (stderr)

magictree.cpp:11:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   11 | void merge(auto& x, auto& y) {
      |            ^~~~
magictree.cpp:11:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   11 | void merge(auto& x, auto& y) {
      |                     ^~~~
#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...